分词器¶
目前,Lance 内置支持 Jieba 和 Lindera。但是,它不自带语言模型。如果需要分词,可以自行下载语言模型。您可以通过设置环境变量 LANCE_LANGUAGE_MODEL_HOME 来指定语言模型存储的位置。如果未设置,默认值为
它还支持配置用户词典,方便用户在不重新训练语言模型的情况下扩展自己的词典。
Jieba 语言模型¶
下载模型¶
语言模型默认存储在 ${LANCE_LANGUAGE_MODEL_HOME}/jieba/default
。
使用模型¶
用户词典¶
在当前模型的根目录中创建一个名为 config.json 的文件。
- "main" 字段是可选的。如果未填写,默认为 "dict.txt"。
- "users" 是用户词典的路径。有关用户词典的格式,请参阅 https://github.com/messense/jieba-rs/blob/main/src/data/dict.txt。
Lindera 语言模型¶
下载模型¶
请注意,Lindera 的语言模型需要编译。请先安装 lindera-cli。有关详细步骤,请参阅 https://github.com/lindera/lindera/tree/main/lindera-cli。
语言模型默认存储在 ${LANCE_LANGUAGE_MODEL_HOME}/lindera/[ipadic|ko-dic|unidic]
使用模型¶
用户词典¶
在模型的根目录中创建一个名为 config.yml 的文件,或使用 LINDERA_CONFIG_PATH
环境变量指定自定义 YAML 文件。如果两者都提供,将使用根目录中的 config.yml。有关更详细的配置方法,请参阅 lindera 文档:https://github.com/lindera/lindera/。
segmenter:
mode: "normal"
dictionary:
# Note: in lance, the `kind` field is not supported. You need to specify the model path using the `path` field instead.
path: /path/to/lindera/ipadic/main
创建你自己的语言模型¶
将您的语言模型放入 LANCE_LANGUAGE_MODEL_HOME
。