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

IndexError: index out of range in self #1906

Closed
1 task done
7777fsq opened this issue Sep 5, 2024 · 1 comment
Closed
1 task done

IndexError: index out of range in self #1906

7777fsq opened this issue Sep 5, 2024 · 1 comment
Assignees
Labels

Comments

@7777fsq
Copy link

7777fsq commented Sep 5, 2024

Describe the bug
A clear and concise description of what the bug is.

Code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate the problem.

sen_tok=['哈哈' for i in range(513)]
ner = hanlp.load(hanlp.pretrained.ner.MSRA_NER_ELECTRA_SMALL_ZH)
ner_tok = ner(sen_tok, tasks='ner*')

Describe the current behavior
A clear and concise description of what happened.
当运行ner = hanlp.load(hanlp.pretrained.ner.MSRA_NER_ELECTRA_SMALL_ZH)
ner_tok = ner(sen_tok, tasks='ner*') # 得出NER结果时
如果token数量刚好是513,那么会出现下列错误:
File "C:\Users\xxxxxx\.conda\envs\NER\Lib\site-packages\hanlp\layers\transformers\relative_transformer.py", line 94, in forward
embed = self.weights.index_select(0, positions.long()).detach()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
IndexError: index out of range in self
感觉可能是因为该代码扩展embedding的73行判断边界条件:
if max_pos > self.origin_shift:
没取等号导致的,取等号后可正常输出,其他数量也都ok
Expected behavior
A clear and concise description of what you expected to happen.
正常输出

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04):
  • Python version:3.12
  • HanLP version:2.1.0

Other info / logs
Include any logs or source code that would be helpful to diagnose the problem. If including tracebacks, please include the full traceback. Large logs and files should be attached.

  • I've completed this form and searched the web for solutions.
@hankcs
Copy link
Owner

hankcs commented Sep 8, 2024

感谢反馈,已经修复,请检查上面的commit是否解决了这个问题。
如果还有问题,欢迎重开issue。

@hankcs hankcs closed this as completed Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants