mpqa围绕争论词汇的spacy扩展
spacy-arguing-lexicon的Python项目详细描述
< H1> SPAY辩论词典
环绕arguing lexicon by MPQA的spaCy扩展。 它允许容易的编程访问包含辩论词典的标记句子。使用spacy,您可以轻松应用最新的机器学习技术。
以辩论词典扩展为例进行深度论证挖掘。有英语和荷兰语两种版本。
开始
您可以通过pip安装spacy扩展。它需要Spacy2。
pip install spacy_arguing_lexicon
python -m spacy download en # optional, downloads a spaCy language model if you haven't downloaded one already
然后通过向SPACY流水线添加辩论词典解析器来启用扩展。
importspacyfromspacy_arguing_lexiconimportArguingLexiconParsernlp=spacy.load("en")nlp.add_pipe(ArguingLexiconParser(lang=nlp.lang))
现在您可以加载任何文档并访问该文档中包含参数的部分。
您可以通过doc._.arguments
属性访问这些参数,该属性由这个扩展添加。
doc=nlp(""" A changing society should not cling to traditional family models. Society is changing, and the traditional idea of the nuclear family with married mother and father is no longer the only acceptable alternative.""")argument_span=next(doc._.arguments.get_argument_spans())print("Argument lexicon:",argument_span.text)print("Label of lexicon:",argument_span.label_)print("Sentence where lexicon occurs:",argument_span.sent.text.strip())
以上将输出
Argument lexicon: should
Label of lexicon: necessity
Sentence where lexicon occurs: A changing society should not cling to traditional family models.
as get_argument_spans
产生spaCy Spans
检索包含有争议词汇的句子的平均词嵌入等事情是微不足道的。
这些平均的嵌入可以作为您深入学习模型的输入。
例如,可以使用包含
的参数词典访问内置的SPAY向量。print("Vector type:",type(argument_span.sent.vector))print("Vector shape:",argument_span.sent.vector.shape)
将输出
Vector type: <class 'numpy.ndarray'>
Vector shape: (384,)
工作原理
MPQA辩论词典可在GNU通用公共许可证下使用。 它是一组大约200个正则表达式,宏分为17类。 有关创建词典的更多信息,请参阅arguing lexicon homepage。
《荷兰语辩论词典》是英语词汇的一种翻译,只有通过这一扩展才可获得。在引擎盖下,这个扩展解析正则表达式并解压其中的任何宏。 ^ {CD3}}方法试图匹配任何词汇正则表达式与输入{^ a5}的文本。 当找到匹配项时,该匹配项将在生成之前转换为spaCy Span。
doc._.arguments.get_argument_spans
是目前唯一推荐使用此扩展的方法。
引文
使用本软件时,请引用以下内容:
Swapna Somasundaran, Josef Ruppenhofer and Janyce Wiebe (2007) Detecting Arguing and Sentiment in Meetings,
SIGdial Workshop on Discourse and Dialogue, Antwerp, Belgium, September 2007 (SIGdial Workshop 2007)