python - 函数后返回的语法
问题描述
我尝试从 gensim 重现这行代码
import gensim
def coherence_values_computation(dictionary, corpus, texts, limit, start=2, step=3):
coherence_values = []
model_list = []
for num_topics in range(start, limit, step):
model = gensim.models.wrappers.LdaMallet(
mallet_path, corpus=corpus, num_topics=num_topics, id2word=id2word
)
model_list.append(model)
coherencemodel = CoherenceModel(
model=model, texts=texts, dictionary=dictionary, coherence='c_v'
)
coherence_values.append(coherencemodel.get_coherence())
return model_list, coherence_values
但是在返回函数中,我收到此错误:
File "<ipython-input-10-65490721eef3>", line 13 return model_list, coherence_values) ^ SyntaxError: invalid syntax
发生这种情况有什么想法吗?
解决方案
return
应该在函数内部。缩进应该是:
def coherence_values_computation(dictionary, corpus, texts, limit, start=2, step=3):
coherence_values = []
model_list = []
for num_topics in range(start, limit, step):
model = gensim.models.wrappers.LdaMallet(
mallet_path, corpus=corpus, num_topics=num_topics, id2word=id2word
)
model_list.append(model)
coherencemodel = CoherenceModel(
model=model, texts=texts, dictionary=dictionary, coherence='c_v'
)
coherence_values.append(coherencemodel.get_coherence())
return model_list, coherence_values
推荐阅读
- java - 通过java访问Sas url时出错,Server无法验证请求
- android - 如何定义 MultiDex 和 ProGuard 规则以防止在 Android 中使用 GooglePlus 登录出现“NoClassDefFoundError”?
- r - 通过部分数据点名称子集数据帧
- android - 约束布局不当行为
- javascript - 检查 div-container 是否有多个 div-inner no jQuery
- common-lisp - 让 asdf 加载目录中的所有文件
- azure - 部署容器组时如何运行多个命令?
- java - 如何在Java中的同一个按键上分配两个动作?
- microsoft-graph-api - 术语财产的目的
- python - 如何将路径传递给变量(Python)