You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法使用quanteda::dictionary()定位字典文件的求助

解决quanteda Seeded LDA教程中字典文件不存在的问题

运行教程代码:

dict_topic <- dictionary(file = "../dictionary/topics.yml")
print(dict_topic)

出现报错:

Error in dictionary.default(file = "../dictionary/topics.yml") :
File does not exist: ../dictionary/topics.yml

原因说明

这个topics.yml字典文件不是quanteda包自带的组件,是教程配套的示例自定义字典,所以本地quanteda文件夹里找不到是正常的,不需要重新安装包。

解决步骤

  • 手动创建字典文件
    Seeded LDA的核心是种子字典,你可以自己编写YAML格式的字典文件。比如参考教程逻辑创建一个topics.yml,内容示例:

    economy:
      - growth
      - inflation
      - unemployment
    politics:
      - election
      - policy
      - government
    

    把这个文件保存到你指定的路径(比如创建一个dictionary子文件夹存放)。

  • 修正文件路径
    确保代码里的路径和你实际存放文件的位置一致:

    • 如果字典文件放在当前工作目录的dictionary子文件夹里,用相对路径:"./dictionary/topics.yml"
    • 或者直接使用绝对路径(比如Windows:"C:/your-folder/dictionary/topics.yml",Mac/Linux:"/home/your-folder/dictionary/topics.yml")
  • 检查工作目录
    用以下代码确认当前工作目录,避免路径错误:

    getwd() # 查看当前工作目录
    setwd("/path/to/your/folder") # 切换到字典所在的父目录
    

内容的提问来源于stack exchange,提问作者KAR

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.11 14:30:57