RASA NLU 中实体注释有空格

Kun*_*jee 1 c# nlp rasa-nlu

我正在查看训练数据 RASA 格式,详细信息请参见此处。

{
  "text": "show me chinese restaurants",
  "intent": "restaurant_search",
  "entities": [
    {
      "start": 8,
      "end": 15,
      "value": "chinese",
      "entity": "cuisine"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

子字符串Chinese被标记为话语第 8 到 15 个索引的实体。

我编写了一个小型 C# 程序来验证话语中字符索引的正确性。

public class Program
    {
        public static void Main(string[] args)
        {
            string s = "show me chinese restaurants";
            int i = 0;

            foreach(var item in s.ToCharArray())
                Console.WriteLine("{0} - {1}", item, i++);
        }
    }
Run Code Online (Sandbox Code Playgroud)

但是当我运行该程序时,我得到以下输出:

s - 0
h - 1
o - 2
w - 3
  - 4
m - 5
e - 6
  - 7
c - 8
h - 9
i - 10
n - 11
e - 12
s - 13
e - 14
  - 15
r - 16
e - 17
s - 18
t - 19
a - 20
u - 21
r - 22
a - 23
n - 24
t - 25
s - 26
Run Code Online (Sandbox Code Playgroud)

请注意文本注释的奇怪行为,子字符串Chinese从索引 8 开始,以空格结束于 15。

但子字符串Chinese应从索引 8 开始,到位置 14 结束。

Chinese当我用从位置 8 开始到 14 结束的索引训练相同的文本时。我收到Misaligned Entity AnnotationRASA 的警告,详细信息请参见此处

有人可以解释这种奇怪的行为吗?

谢谢

Mar*_*ies 5

阅读提供的链接我可能会想出一个可能的解释:

它们一起构成一个适用于字符串的 python 样式范围,例如在下面的示例中,使用 text="show me chineserestaurants",然后 text[8:15] == 'chinese'

这引导我走上了一条我正在思考的道路

嗯,这很奇怪,我想知道 python 是否会奇怪地进行索引

我开发了一个快速应用程序来证明这一点:

text = "show me chinese restaurants"
print(text[8:15])
Run Code Online (Sandbox Code Playgroud)

现在这可能没有意义,因为这里数组的第 15 个空格中的字符实际上是一个空格。这让我想到了这篇文章:

https://www.pythoncentral.io/how-to-slice-listsarrays-and-tuples-in-python/

看起来他们在示例中使用的运算符对text[8:15]数组进行了切片,他们使用了以下示例:

a = [1, 2, 3, 4, 5, 6, 7, 8]

a[1:4]其输出:[2, 3, 4]

并这样解释

让我解释一下。1 表示从列表中的第二个元素开始(请注意,切片索引从 0 开始)。4 表示结束于列表中的第五个元素,但不包含它。中间的冒号是 Python 列表如何识别我们要使用切片来获取列表中的对象的方式。

所以看来切片的第二个参数是排他的。

希望这可以帮助

ps 必须学习和设置一些 python 东西:D