【发布时间】:2019-08-18 09:46:08
【问题描述】:
我做了一个快速实验来检查苹果自然语言框架中词形还原的准确性,结果很差。
我想知道是我做错了什么还是框架真的那么糟糕。
对于实验,我直接使用了 Apple 文档中的代码(在我能找到的几个在线示例中也有重复)。
let tagger = NLTagger(tagSchemes: [.lemma])
tagger.string = text
let options: NLTagger.Options = [.omitPunctuation, .omitWhitespace]
tagger.enumerateTags(in: text.startIndex..<text.endIndex, unit: .word, scheme: .lemma, options: options) { tag, tokenRange in
print("\(text[tokenRange]): \(tag?.rawValue ?? "NO LEMMA")")
return true
}
为了测试输出,我从 Euronews 的一篇文章中摘录了一段,该文章有多种语言版本。
英文版似乎准确,但在英文中,大多数单词都与它们的引理一致,所以它不是一个很好的基准。
我在 macOS 10.14.6 上的 Xcode Playground 中运行代码。我尝试了 macOS 和 iOS 作为 Playground 的平台,这没什么区别。
let text = "For the possible necessity of short-time work I want to make sure to build an incentive with connecting it to training. And I want Germany to be able to implement short-time work faster in case of a fast recession of the economic situation because of global economic risks."
// Output
For: for
the: the
possible: possible
necessity: necessity
of: of
short: short
time: time
work: work
I: I
want: want
to: to
make: make
sure: sure
to: to
build: build
an: an
incentive: incentive
with: with
connecting: connect
it: it
to: to
training: training
And: and
I: I
want: want
Germany: Germany
to: to
be: be
able: able
to: to
implement: implement
short: short
time: time
work: work
faster: fast
in: in
case: case
of: of
a: a
fast: fast
recession: recession
of: of
the: the
economic: economic
situation: situation
because: because
of: of
global: global
economic: economic
risks: risk
然后我尝试了意大利语,这是我的母语,所以我可以很容易地验证它。在这里我开始看到一些问题。
let text = "Voglio assicurare che siano creati degli incentivi nel settore del lavoro a orario ridotto, collegati con periodi di training. E voglio che la Germania sia in grado di incrementare questo tipo di offerta lavorativa in modo veloce, in caso di recessione dell'economia per non farsi travolgere dai rischi che a livello globale subiremmo."
// Output
Voglio: volersi
assicurare: assicurare
che: che
siano: essersi
creati: crearsi
degli: degli
incentivi: incentivo
nel: nel
settore: settore
del: del
lavoro: lavoro
a: a
orario: orario
ridotto: ridotto
collegati: collegarsi
con: con
periodi: periodo
di: di
training: training
E: e
voglio: volersi
che: che
la: la
Germania: Germania
sia: essersi
in: in
grado: grado
di: di
incrementare: incrementare
questo: questo
tipo: tipo
di: di
offerta: offerta
lavorativa: lavorativo
in: in
modo: modo
veloce: veloce
in: in
caso: caso
di: di
recessione: recessione
dell'economia: economia
per: per
non: non
farsi: farsi
travolgere: travolgere
dai: dai
rischi: rischio
che: che
a: a
livello: livello
globale: globale
subiremmo: subire
这里有些动词有奇怪的引理:“volersi”、“essersi”、“crearsi”不是这些动词的正确不定式。出于某种原因,它们处于反身形式。但问题是,在示例句子的许多部分中,它们没有被反身使用。
但是当我尝试使用俄语(我说的是中级水平)时,事情才真正崩溃。
let text = "Чтобы быть готовыми к потенциальному появлению необходимости в краткосрочной работе, я хочу создать возможности для обучения. Я хочу, чтобы Германия могла быстро выполнять работу в самые сжатые сроки в случае быстрого спада экономики из-за нависших над ней глобальных рисков."
// Output
Чтобы: чтобы
быть: быть
готовыми: NO LEMMA
к: к
потенциальному: NO LEMMA
появлению: NO LEMMA
необходимости: NO LEMMA
в: в
краткосрочной: NO LEMMA
работе: NO LEMMA
я: я
хочу: NO LEMMA
создать: NO LEMMA
возможности: NO LEMMA
для: для
обучения: NO LEMMA
Я: я
хочу: NO LEMMA
чтобы: чтобы
Германия: Германия
могла: мочь
быстро: NO LEMMA
выполнять: NO LEMMA
работу: NO LEMMA
в: в
самые: самый
сжатые: NO LEMMA
сроки: NO LEMMA
в: в
случае: случай
быстрого: NO LEMMA
спада: спад
экономики: NO LEMMA
из: из
за: за
нависших: NO LEMMA
над: над
ней: ней
глобальных: NO LEMMA
рисков: риск
这里大多数词都不会产生引理。这些不是稀有词,在我看来,它们也不应该难以词形化(但我不是 NLP 专家)。
例如,单词“быстро”(快,快)是最常用的 300 个俄语单词之一,是形容词“быстрый”的副词。这绝对是我希望词形还原器识别的词。就像“хочу”这个词是“我想要”。
意大利的输出已经让我感到困惑,但俄罗斯的输出肯定无法使用。
是我做错了什么,还是苹果的框架真的那么糟糕?
【问题讨论】:
标签: ios macos nlp lemmatization