Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

添加词之后出现的报错 #678

Open
Jing-XING opened this issue Nov 15, 2023 · 0 comments
Open

添加词之后出现的报错 #678

Jing-XING opened this issue Nov 15, 2023 · 0 comments

Comments

@Jing-XING
Copy link

对于ltp4.2.0,在使用add_words之后特殊情况下的报错。直觉上是添加了word(如‘abc')之后,输入类似”xabc“这样的词会出现这样的问题:
输入

ltp.add_words(['800000股'])
ltp.pipeline(['3800000股'], tasks=["cws", "pos"])

报错信息为KeyError

Traceback (most recent call last)
Cell In[57], line 1
----> 1 ltp.pipeline(['3800000股'], tasks=["cws", "pos"])

File D:\software\anaconda\envs\EDEE\lib\site-packages\ltp\nerual.py:24, in no_grad.<locals>.wrapper(*args, **kwargs)
     22 def wrapper(*args, **kwargs):
     23     with torch.no_grad():
---> 24         return func(*args, **kwargs)

File D:\software\anaconda\envs\EDEE\lib\site-packages\ltp\nerual.py:185, in LTP.pipeline(self, inputs, tasks, raw_format, return_dict)
    183         cache[cache_key] = (hidden_state, attention_mask)
    184     result = self.model.task_heads[task](hidden_state, attention_mask)
--> 185     store[task] = self.post[task](result, hidden, store, inputs, tokenized)
    187 if not raw_format:
    188     if is_split_into_words:

File D:\software\anaconda\envs\EDEE\lib\site-packages\ltp\nerual.py:24, in no_grad.<locals>.wrapper(*args, **kwargs)
     22 def wrapper(*args, **kwargs):
     23     with torch.no_grad():
---> 24         return func(*args, **kwargs)

File D:\software\anaconda\envs\EDEE\lib\site-packages\ltp\nerual.py:293, in LTP._cws_post(self, result, hidden, store, inputs, tokenized)
    291 for i, e in enumerate(word_end):
    292     if i == 0:
--> 293         entities[-1].append((0, length2index[e]))
    294     else:
    295         entities[-1].append((length2index[word_end[i - 1]] + 1, length2index[e]))

KeyError: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant