【问题标题】:Identifying natural languages from small samples in Python从 Python 中的小样本中识别自然语言
【发布时间】:2021-10-23 12:29:22
【问题描述】:

使用 Python,我想在一个短字符串列表(从 1 到大约 50 个单词)中识别法语文本,否则它们是英文的。

输入数据示例(此处输入字符串以逗号分隔):

year of the snake, legendary 'dragon horse', thunder, damsel-fly, larvae of mosquito, 
treillage, libellule, mythical water creature, petites chevrettes, de papillon hideux, 
the horse-fly, 5th earthly branch, dragon, mythical creature, 
a shore plant whose leaves dry a bright orange, dragon horse, god of rain, year of the dragon, 
orthopteran, crocodile, dont le duvet des ailes s'en va en poussière, insecte, dragonfly, 
dracontomelon vitiense, dragon king, petit filet pour une espèce de papillon, sorte d'insecte

理想情况下,我想使用已经构建好的库,因为我知道这是一个难题。但是,我最熟悉的Python中的自然语言库nltk,似乎没有这个能力,或者如果有,我也没找到。

我知道识别一两个单词可能非常困难,我宁愿误报(法语误认为英语)也不愿误报。

【问题讨论】:

  • 有数据集和NN模型herehere这样做!

标签: python nlp nltk


【解决方案1】:

有多种方法可以解决这个问题。一个更传统和更准确(但也容易出现新词问题)的方法是使用thesaurus for French and English 并检查是否在其中一个或另一个中找到该短语(完全匹配或多个单词匹配)。

另一种是使用language detection的包。

还有一个是 use an ML language model 对短语进行分类(例如 SpaCy lang_detect model)。

【讨论】:

  • 谢谢!我选择使用 langid,因为它在我查看的数据上具有最佳性能,但 langdetect(Jordi Carr 在 nltk-users 邮件列表中也建议)和 cld3 也是此任务的可行选项。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-01-31
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-10-22
  • 1970-01-01
相关资源
最近更新 更多