首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >AttributeError:“spacy.tokens.doc.Doc”对象没有“”lower“”属性“”

AttributeError:“spacy.tokens.doc.Doc”对象没有“”lower“”属性“”
EN

Stack Overflow用户
提问于 2020-03-10 22:22:21
回答 1查看 5.9K关注 0票数 1

我的工作是在列表中添加文本,然后将文本更改为单词嵌入,然后进行机器学习。“文章”中的“insts”是使用spacy来收集的,但是我遇到了下面这个错误,有人能告诉我如何修复这个错误吗?我可以将类型‘’str y.tokens.doc.Doc‘改为'str’吗?

代码语言:javascript
复制
def main(annotations_file, max_insts=-1):
    articles = reader.read_corpus(annotations_file,max_insts=max_insts)
    texts=[]
    random.seed(5)
    random.shuffle(articles)
    # arti = list()
    sect = list()
    label_bef=list()
    label_dur=list()
    label_aft=list()

    for insts in articles:
        for inst in insts:
            texts.append(inst.possessor.doc._.article_title_doc)
            #sect.append(inst.possessor.doc._.section_title_doc)
            label_bef.append(inst.labels['BEF'])
            label_dur.append(inst.labels['DUR'])
            label_aft.append(inst.labels['AFT'])

    embeddings_index = {}
    with open('glove.6B.100d.txt') as f:
        for line in f:
            word, coefs = line.split(maxsplit=1)
            coefs = np.fromstring(coefs, 'f', sep=' ')
            embeddings_index[word] = coefs

    tokenizer = Tokenizer(num_words=MAX_NUM_WORDS)
    tokenizer.fit_on_texts(texts)
    word_index = tokenizer.word_index
代码语言:javascript
复制
Traceback (most recent call last):
   File "sample.py", line 117, in <module>
     main(args.ANNOTATIONS_FILE, args.max_articles)
   File "sample.py", line 51, in main
     tokenizer.fit_on_texts(texts)
   File "/home/huweilong/miniconda3/envs/nre/lib/python3.6/site-packages/keras_preprocessing/text.py", line 223, in fit_on_texts
self.split)
   File "/home/huweilong/miniconda3/envs/nre/lib/python3.6/site-packages/keras_preprocessing/text.py", line 43, in text_to_word_sequence
     text = text.lower()
   AttributeError: 'spacy.tokens.doc.Doc' object has no attribute 'lower'
EN

回答 1

Stack Overflow用户

发布于 2020-03-25 18:18:32

您可以通过调用doc.text来获取spaCy文档的字符串表示。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60619572

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档