ltp
ltp copied to clipboard
Big Bug: program error and exit
When using the LTP/legacy model, if the input text is empty, it will cause rust to report an error and exit.
During batch data processing, empty or abnormal content will appear in the middle, causing the program to crash, and the exception cannot be handled using python's try catch.
Below is the usage code:
from ltp import LTP
ltp = LTP("LTP/legacy")
sentence = ""
result = ltp.pipeline(sentence, tasks=["cws", "pos"])
print(result)
The error message is as follows:
oading weights from local directory
thread '<unnamed>' panicked at 'index out of bounds: the len is 0 but the index is 0', /home/runner/work/ltp/ltp/rust/ltp/src/perceptron/model.rs:130:30
stack backtrace:
0: rust_begin_unwind
at /rustc/36fb58e433c782e27dd41034284e157cf86d587f/library/std/src/panicking.rs:593:5
1: core::panicking::panic_fmt
at /rustc/36fb58e433c782e27dd41034284e157cf86d587f/library/core/src/panicking.rs:67:14
2: core::panicking::panic_bounds_check
at /rustc/36fb58e433c782e27dd41034284e157cf86d587f/library/core/src/panicking.rs:162:5
3: ltp::perceptron::model::Perceptron<ltp::perceptron::definition::cws::CWSDefinition,Feature,ParamStorage,Param>::predict
4: ltp_extension::perceptron::specialization::cws::PyCWSModel::predict
5: ltp_extension::perceptron::specialization::cws::_::<impl ltp_extension::perceptron::specialization::cws::PyCWSModel>::__pymethod___call____
6: pyo3::impl_::trampoline::trampoline_inner
7: ltp_extension::perceptron::specialization::cws::_::<impl pyo3::impl_::pyclass::PyMethods<ltp_extension::perceptron::specialization::cws::PyCWSModel> for pyo3::impl_::pyclass::PyClassImplCollector<ltp_extension::perceptron::specialization::cws::PyCWSModel>>::py_methods::ITEMS::trampoline
8: PyObject_Call
at /usr/local/src/conda/python-3.7.16/Objects/call.c:245:19
9: do_call_core
at /usr/local/src/conda/python-3.7.16/Python/ceval.c:4645:16
10: _PyEval_EvalFrameDefault