You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
tokenizer: position_factor mixes character-length with token-index #3811
The intent — based on the comment one line above — is "words at the beginning and end of the sentence are more important". But len(text) / 3 is computed against the raw character string, not the number of tokens. For any reasonable Chinese query of more than ~10 characters, len(text)/3 is already larger than the actual number of tokens, so the idx > len(text)/3 branch never fires and only the first three tokens get the boost. For short queries the opposite happens: nearly every token gets boosted.
Repro
fromnexent.core.nlp.tokenizerimportcalculate_term_weights# 30-char sentence with ~10 tokens; len(text)/3 == 10 �� "end-of-sentence" boost never appliesprint(calculate_term_weights("人工智能在医疗影像识别中的应用与前景分析"))
Expected
position_factor should be a function of position within the token stream, e.g.:
n_tokens_estimate=max(1, len(text) //2) # or pre-tokenize firstposition_factor=1.2ifidx<3oridx>=n_tokens_estimate-3else1.0
A cleaner fix is to materialize pseg.cut(text) into a list first and use len(words) as the denominator.
Severity
Medium — search ranking quality is degraded but the function still returns something usable.
Activity