文档帮助中心文档
将文档转换为低维空间
DScores = Transform(LSAMDL,文档)
DScores =变换(LSAMDL,BAG)
dscores =变换(lsaMdl计数)
dscores =变换(ldaMdl、文档)
dscores =变换(ldaMdl袋)
dscores =变换(ldaMdl计数)
dscores =变换(___、名称、值)
例子
dscores.=变换(lsaMdl那文件)将文档转换为潜在语义分析(LSA)模型的语义空间lsaMdl.
dscores.=变换(lsaMdl那文件)
dscores.
lsaMdl
文件
dscores.=变换(lsaMdl那包)转换由单词袋或N-r克模型表示的文件包进入LSA模型的语义空间lsaMdl.
dscores.=变换(lsaMdl那包)
包
dscores.=变换(lsaMdl那算)将单词计数矩阵表示的文档转换到LSA模型的语义空间中lsaMdl.
dscores.=变换(lsaMdl那算)
算
dscores.=变换(ldaMdl那文件)将文档转换为LDA模型的潜在Dirichlet分配(LDA)主题概率空间ldaMdl.的行dscores.是文件的混合物表示的主题。
dscores.=变换(ldaMdl那文件)
ldaMdl
dscores.=变换(ldaMdl那包)转换由单词袋或N-r克模型表示的文件包进入LDA模型的LDA主题概率空间ldaMdl.
dscores.=变换(ldaMdl那包)
dscores.=变换(ldaMdl那算)将单词计数矩阵表示的文档转换为LDA模型的LDA主题概率空间ldaMdl.
dscores.=变换(ldaMdl那算)
dscores.=变换(___那名称,值)使用一个或多个名称-值对参数指定其他选项。这些名称-值对仅在输入模型是Ldamodel.对象。
dscores.=变换(___那名称,值)
名称,值
Ldamodel.
全部折叠
加载示例数据。文件sonnetsPreprocessed.txt包含Precrocessed版本的莎士比亚的十四行诗。该文件每行包含一个十四行诗,单词由空格分隔。从中提取文本sonnetsPreprocessed.txt,将文本拆分为换行符的文档,然后授权文档。
sonnetsPreprocessed.txt
filename =.“sonnetsPreprocessed.txt”;str = inthelfiletext(filename);textdata = split(str,newline);文档= tokenizeddocument(textdata);
创建一个词袋模型使用Bagofwords..
Bagofwords.
袋= bagOfWords(文档)
单词:[" fairrest " "creatures" "desire"…NumWords: 3092 NumDocuments: 154
适合20个组件的LSA模型。
numCompnents = 20;numCompnents mdl = fitlsa(袋)
mdl = lsammodel with properties: NumComponents: 20 ComponentWeights: [2.7866e+03 515.5889 443.6428 316.4191…词汇:[" fairmost " "creatures" "desire"…] FeatureStrengthExponent: 2
使用变换将前10个文档转换为LSA模型的语义空间。
变换
dscores =变换(mdl、文档(1:10))
dscores =10×205.6059 -1.8559 0.9286 -0.7086 -0.4652 -0.8340 0.6751 0.0611 0.2268 1.9320 -0.7289 -1.0864 0.7131 -0.0571 -0.3401 0.0940 -0.4406 1.7507 -1.1534 0.1785 7.3069 -2.3578 1.8359 -2.3442 -1.5776 -2.0310 0.7948 1.3411 -1.1700 1.8839 0.0883 -1.1244 0.6795 1.3585 -0.0247 0.3627 -0.5414 -0.0272 -0.0114 7.1056 -2.3508 -2.8837 -1.0688 -0.3462 -0.69620.0334 -0.0472 0.4916 0.6496 -1.1959 -1.0171 -0.4020 1.2953 -0.4583 0.5984 -0.3890 1.1780 0.6413 0.6575 8.6292 -3.0471 -0.8512 -0.4356 -0.3055 0.4671 - 1.8454 -0.8270 0.4122 2.2082 -1.1770 1.7775 -2.2344 -2.7813 1.4979 0.7486 -2.0593 0.6376 1.0721 1.0434 1.7490 0.8703 -2.2315 -1.1221 0.2848 -2.0522 -0.6975 1.7191 0.2852 0.8879 0.99500.5555 0.8842 -0.0360 1.0050 0.4158 0.5061 0.9602 0.4672 6.8358 -2.0806 -3.3798 -1.0452 -0.2075 2.0970 -0.4477 0.2080 1.6203 0.6653 0.0036 1.0825 0.6396 -0.2154 -0.0794 0.71080.4817 0.7925 -0.3941 -4.4610 -0.4930 0.4651 - 0.3404 -0.5493 - 1470 0.5065 0.2566 0.3394 -1.1529 -0.0391 -0.8800 -0.4712 0.9672 0.5457 -0.3639 -0.3085 0.5637 0.6522 0.7188 -1.1787 -0.8996 0.3360 0.4531 -0.1935 0.3328 -0.8640 -1.6679 -0.8056 -2.1993 0.1808 0.0163 -0.9520 -0.8982 0.6603 3.6451 1.2412 1.9621 8.8218 -0.8168 -2.5101 1.1197 -0.8673-1.2336 0.0768 0.1943 -0.7629 -0.1222 0.3786 1.1611 0.2326 0.3415 -0.3327 -0.3792 1.7554 0.2526 -2.1574 -0.0193
在此示例中重现结果,设置rng到“默认”.
rng
“默认”
rng (“默认”)
拟合具有五个主题的LDA模型。
numTopics = 5;numTopics mdl = fitlda(袋)
初始主题分配在0.102958秒内采样。===================================================================================== |迭代|每个时间|相对|训练|主题|主题||| iteration | change in | perplexity | concentration | concentration | | | (seconds) | log(L) | | | iterations | ===================================================================================== | 0 | 0.00 | | 1.212e+03 | 1.250 | 0 | | 1 | 0.01 | 1.2300e-02 | 1.112e+03 | 1.250 | 0 | | 2 | 0.02 | 1.3254e-03 | 1.102e+03 | 1.250 | 0 | | 3 | 0.01 | 2.9402e-05 | 1.102e+03 | 1.250 | 0 | =====================================================================================
WordConcentration: 1 TopicConcentration: 1.2500 corpustopicprobability: [0.2000 0.2000 0.2000 0.2000 0.2000 0.2000 0.2000] documenttopicprobability: [154x5 double] topicwordprobability: [3092x5 double]TopicOrder: 'initial-fit-probability'
使用变换将文档转换为主题概率向量。您可以使用堆叠的柱状图来可视化这些混合物。查看前10个文档的主题混合。
topicMixtures =变换(mdl、文档(1:10));图barh (topicMixtures,“堆叠”) xlim([0 1]) title(“主题混合”)包含(“主题概率”) ylabel (“文档”)传说(“主题”+字符串(1:numTopics),“位置”那“northeastoutside”)
加载示例数据。sonnetsCounts.mat包含一个单词计数矩阵和相应的词汇预处理版本的莎士比亚十四行诗。
sonnetsCounts.mat
负载sonnetsCounts.mat大小(数量)
ans =1×2154 3092
拟合具有20个主题的LDA模型。在此示例中重现结果,设置rng到“默认”.
rng (“默认”)numtopics = 20;mdl = fitlda(计数,numtopics)
初始主题分配在0.13535秒内采样。===================================================================================== |迭代|每个时间|相对|训练|主题|主题||| iteration | change in | perplexity | concentration | concentration | | | (seconds) | log(L) | | | iterations | ===================================================================================== | 0 | 0.03 | | 1.159e+03 | 5.000 | 0 | | 1 | 0.05 | 5.4884e-02 | 8.028e+02 | 5.000 | 0 | | 2 | 0.04 | 4.7400e-03 | 7.778e+02 | 5.000 | 0 | | 3 | 0.03 | 3.4597e-03 | 7.602e+02 | 5.000 | 0 | | 4 | 0.03 | 3.4662e-03 | 7.430e+02 | 5.000 | 0 | | 5 | 0.03 | 2.9259e-03 | 7.288e+02 | 5.000 | 0 | | 6 | 0.03 | 6.4180e-05 | 7.291e+02 | 5.000 | 0 | =====================================================================================
mdl = ldaModel with properties: NumTopics: 20 WordConcentration: 1 TopicConcentration: 5 corpustopic概率:[0.0500 0.0500 0.0500 0.0500 0.0500…词汇:["1" "2" "3" "4" "5"…TopicOrder: 'initial-fit-probability'
使用变换将文档转换为主题概率向量。
topicMixtures =变换(mdl计数(1:10,:))
topicMixtures =10×200.0167 0.0035 0.1645 0.0977 0.0433 0.0833 0.0987 0.0033 0.0299 0.0234 0.0033 0.0345 0.0235 0.0958 0.0667 0.0519 0.0833 0.0300 0.0711 0.0544 0.0116 0.0044 0.0033 0.0033 0.0431 0.0053 0.0145 0.0421 0.0971 0.0033 0.0040 0.1632 0.1784 0.0937 0.0683 0.0398 0.0954 0.0037 0.0293 0.0482 0.01078 0.0064 0.06120.0036 0.0176 0.0036 0.0464 0.0906 0.1169 0.0888 0.1115 0.1180 0.0607 0.0055 0.0962 0.2403 0.0033 0.0296 0.1613 0.0164 0.0955 0.0163 0.0045 0.0415 0.0404 0.0342 0.0176 0.0417 0.0642 0.0033 0.0676 0.0341 0.0341 0.0948 0.0038 0.01099 0.0187 0.0560 0.01045 0.0356 0.0668 0.1196 0.0038 0.0931 0.06260.0445 0.0035 0.1167 0.0034 0.0446 0.0583 0.1268 0.01135 0.0034 0.0047 0.0993 0.0909 0.0582 0.0308 0.0887 0.0856 0.0034 0.1720 0.0764 0.0090 0.0180 0.0325 0.1213 0.0036 0.0036 0.0505 0.0472 0.0348 0.0477 0.0039 0.0038 0.0122 0.0041 0.0036 0.1605 0.1487 0.0465 0.0043 0.0033 0.1248 0.0033 0.0299 0.0033 0.01699 0.06950.0033 0.0039 0.0620 0.0833 0.0040 0.0700 0.0033 0.1479 0.0033 0.0433 0.0412 0.0387 0.0555 0.0165 0.0166 0.0433 0.0033 0.0038 0.0048 0.0033 0.0473 0.0474 0.1290 0.1107 0.0089 0.0112 0.0167 0.1555 0.2423 0.0040 0.0362 0.0035 0.1117 0.0304 0.0034 0.1248 0.0439 0.0340 0.0168 0.0714 0.0034 0.0214 0.0056 0.0449 0.1438 0.0036 0.0290 0.0980 0.0304
lsaModel
输入LSA模型,指定为lsaModel对象。
输入LDA模型,指定为一个Ldamodel.对象。
tokenizedDocument
输入文档,指定为atokenizedDocument数组、字的字符串数组或字符向量的单元格数组。如果文件是一个tokenizedDocument,那么它一定是一个列向量。如果文件是字符向量的字符串数组或单元格数组,则它必须是单个文档的一行单词。
提示
为确保该功能不会丢弃有用信息,必须使用用于预处理用于训练模型的文档的相同步骤进行预处理输入文档。
Bagofngrams.
输入bag-of-words或bag-of-n-grams模型,指定为Bagofwords.对象或一个Bagofngrams.对象。如果包是一个Bagofngrams.对象,然后该函数将每个n-gram视为单个单词。
单词频率计数,指定为非负整数的矩阵。如果您指定'documentsin'成为'行',那么值计数(i, j)对应于次数j词汇表中的单词出现在一世文件。否则,值计数(i, j)对应于次数一世词汇表中的单词出现在j文件。
'documentsin'
'行'
计数(i, j)
指定可选的逗号分隔的对名称,值参数。姓名参数名和价值为对应值。姓名必须出现在引号内。可以以任意顺序指定多个名称和值对参数Name1, Value1,…,的家.
姓名
价值
Name1, Value1,…,的家
“IterationLimit”,200年
笔记
这些名称-值对仅在输入模型是Ldamodel.对象。
'列'
文档的方向在单词计数矩阵中,指定为逗号分隔对组成'documentsin'和以下之一:
'行'- 输入是单词计数的矩阵,具有与文档相对应的行。
'列'-输入是一个转置的字数矩阵,其列对应于文档。
此选项仅适用于将输入文档指定为单词计数矩阵的情况。
如果您对单词计数矩阵进行了定位,使文档与列对应并指定'docuidesin','列',然后您可能会遇到优化执行时间的显着减少。
'docuidesin','列'
iterationlimit.
One hundred.
指定为逗号分隔对的最大迭代次数“IterationLimit”一个正整数。
“IterationLimit”
例子:“IterationLimit”,200年
LogLikelihoodTolerance
0.0001.
对数似然的相对容忍度,指定为逗号分隔的对,由'loglikelihoodtolerance'一个正标量。当达到此公差时,优化终止。
'loglikelihoodtolerance'
例子:“LogLikelihoodTolerance”,0.001
“LogLikelihoodTolerance”,0.001
输出文档分数,作为分数向量矩阵返回。
菲达|Fitlsa.|logp|预测|WordCloud.|Bagofwords.|Ldamodel.|lsaModel
菲达
Fitlsa.
logp
预测
WordCloud.
您有这个示例的修改版本。您想打开这个示例与您的编辑吗?
你点击一个链接对应于这个MATLAB命令:
通过在MATLAB命令窗口中输入命令来运行命令。Web浏览器不支持MATLAB命令。金宝app
选择一个网站,以便在可用的地方进行翻译的内容,并查看本地活动和优惠。根据您的位置,我们建议您选择:.
你也可以从以下列表中选择一个网站:
选择中国网站(以中文或英文)以获取最佳网站性能。其他MathWorks国家网站未优化您的位置。
与当地办事处联系