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

[BUG] IndexError #548

Open
v-JiangNan opened this issue Jan 16, 2025 · 2 comments
Open

[BUG] IndexError #548

v-JiangNan opened this issue Jan 16, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@v-JiangNan
Copy link

代码:

from pycorrector import MacBertCorrector

model_path = 'model/macbert4csc-base-chinese'
bert_model = MacBertCorrector(model_name_or_path=model_path)
bert_model.correct_batch(sentences=['标准皮鞋码哈运动鞋码40选39码'], max_length=50, batch_size=4, threshold=0.75)

运行结果:

  File "/home/root/miniconda3/envs/py310/lib/python3.10/site-packages/pycorrector/macbert/macbert_corrector.py", line 97, in correct_batch
    sents = self._predict(
            │    └ <function MacBertCorrector._predict at 0x7fef50b83a30>
            └ <pycorrector.macbert.macbert_corrector.MacBertCorrector object at 0x7fefcae47d30>
  File "/home/root/miniconda3/envs/py310/lib/python3.10/site-packages/pycorrector/macbert/macbert_corrector.py", line 57, in _predict
    if probs[i + 1] >= threshold:
       │     │         └ 0.75
       │     └ 15
       └ array([0.90520966, 1.        , 0.9999956 , 0.9994678 , 0.9999119 ,
                0.99893886, 0.97873324, 0.9999783 , 0.99998116, 0.9...
IndexError: index 16 is out of bounds for axis 0 with size 16

调试了一下发现模型预测结果是:
['码', '标', '准', '皮', '鞋', '码', '哈', '运', '动', '鞋', '码', '40', '选', '39', '码', '码']
明显是错误的,其它句子有时也会出现这种情况。

@v-JiangNan v-JiangNan added the bug Something isn't working label Jan 16, 2025
@shibing624
Copy link
Owner

模型预测错误,错位了。

@v-JiangNan
Copy link
Author

模型预测错误,错位了。

请问如何解决这个问题呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants