Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1789953
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: LINUX

2018-10-07 16:17:13

在123页的pos-tagging with spaCy,我电脑上运行代码的结果和书上的不一致,原因未知。

1. 运行环境

点击(此处)折叠或打开

  1. root@kali:~# ipython3
    Python 3.6.6 (default, Jun 27 2018, 14:44:17)
    Type "copyright", "credits" or "license" for more information.

    IPython 5.5.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.

  2. In [16]: spacy.__version__
  3. Out[16]: '2.0.12'

2.  实际代码,只贴出不一致的两段代码
书中的例子,sent_2中的refuse 在书中是'noun',  而我的结果是refuse ADJ JJ,adjective形容词。
sent_3中,her 在书中是ADJ, 形容词, 而我的结果是her PRON PRP, pronoun代词.
第一个fish在书中是动词verb, 而我的结果是fish NOUN NN, noun 名词。

点击(此处)折叠或打开

  1. In [4]: import spacy

  2. In [5]: nlp=spacy.load('en')

  3. In [6]: sent_0 = nlp('Mathiew and I went to the park.')

  4. In [7]: sent_1 = nlp('If Clement was asked to take out the garbage, he would ref
  5.    ...: use.')

  6. In [8]: sent_2 = nlp('Baptiste was in charge of the refuse treatment center.')

  7. In [9]: sent_3 = nlp('Marie took out her rather suspicious and fishy cat to go f
  8.    ...: ish for fish.')


  9. In [12]: for token in sent_2:
  10.     ...: print(token.text, token.pos_, token.tag_)
  11.     ...:
  12.     ...:
  13. Baptiste PROPN NNP
  14. was VERB VBD
  15. in ADP IN
  16. charge NOUN NN
  17. of ADP IN
  18. the DET DT
  19. refuse ADJ JJ
  20. treatment NOUN NN
  21. center NOUN NN
  22. . PUNCT .


  23. In [15]: for token in sent_3:
  24.     ...: print(token.text, token.pos_, token.tag_)
  25.     ...:
  26. Marie PROPN NNP
  27. took VERB VBD
  28. out PART RP
  29. her PRON PRP
  30. rather ADV RB
  31. suspicious ADJ JJ
  32. and CCONJ CC
  33. fishy ADJ JJ
  34. cat NOUN NN
  35. to PART TO
  36. go VERB VB
  37. fish NOUN NN
  38. for ADP IN
  39. fish NOUN NN
  40. . PUNCT .




阅读(1903) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~