HumanSignal / HumanSignal/label-studio

Named Entity Recognition - Incorrect spans shown after labelling

Open
#4,988 2 comments 2 reactions 0 assignees View on GitHub
community:bug community:reviewed
Dominant language
TypeScript
Stars
28.3k
Forks
3.7k
Avg merge
14h
Merged PRs (30d)
15

Description

**Describe the bug**
In a Named Entity Recognition project the incorrect span is shown after labelling in some cases.

**To Reproduce**
Steps to reproduce the behavior:
1. Create a "Named Entity Recognition" project and import the following as a .txt ("Treat as list of tasks"):
```
👨🏻‍🚒 firemen drive firetrucks at work
```
3. Click "Label All Tasks"
4. Select firetrucks" to be labelled
6. Note "ve firetru" is selected as the label and the end of the text is cut off (see screenshot), but "firetrucks" is correctly marked in the exported JSON.

**Expected behavior**
Selected word is "firetrucks" is highlighted as the labelled span.

**Screenshots**
Screenshot 2023-10-31 at 05 55 32
Screenshot 2023-10-31 at 05 55 46

**Environment (please complete the following information):**
- OS: macOS Ventura 13.6
- Label Studio Version 1.9.1 (Docker)

**Additional context**
I assume this is something related to label indices (start and end) being positions in either a sequence of 16-bit Unicode code units (as they are in TypeScript/JavaScript) or in a sequence of Unicode code points (as they are in Python).

Take `text = "👨🏻‍🚒 firemen drive firetrucks at work"` as an example. Suppose we label the word "firetrucks":
- In TypeScript/JavaScript, the word has start, end = 22, 32
- In Python, the word has start, end = 19, 29, i.e., `text[19:29] == "firetrucks"`

See this [Better Programming article](https://betterprogramming.pub/slicing-strings-containing-emoji-differences-between-python-and-javascript-4716c419718f) for further explanation.

I note that the code unit span (19, 29) (the correct _code point_ span is (19, 29)) corresponds to the code point span (16, 26), for which `text[16:26] == "ve firetru"`, as is displayed.

Possibly related issues:
- https://github.com/HumanSignal/label-studio/issues/4929
- https://github.com/HumanSignal/label-studio/issues/4843
- https://github.com/HumanSignal/label-studio/issues/2777

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.