从 Python 中的小样本中识别自然语言
Identifying natural languages from small samples in Python
使用 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好像没有这个能力,要不我也没找到。
我知道识别一个或两个单词可能非常困难,我宁愿有假阴性(法语被误识别为英语)也不愿假阳性。
有多种方法可以解决这个问题。一种更传统和更准确(但也容易出现新词问题)的方法是使用 thesaurus for French and English 并检查是否在一个或另一个中找到该短语(完全匹配或多个单词匹配)。
另一种是使用包 。
还有一个是 use an ML language model to classify phrases (e.g. SpaCy lang_detect model).
使用 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好像没有这个能力,要不我也没找到。
我知道识别一个或两个单词可能非常困难,我宁愿有假阴性(法语被误识别为英语)也不愿假阳性。
有多种方法可以解决这个问题。一种更传统和更准确(但也容易出现新词问题)的方法是使用 thesaurus for French and English 并检查是否在一个或另一个中找到该短语(完全匹配或多个单词匹配)。
另一种是使用包
还有一个是 use an ML language model to classify phrases (e.g. SpaCy lang_detect model).