gpt4 book ai didi

ios - 在 Swift 中显示 NLTokenizer 的索引、标记

转载 作者:行者123 更新时间:2023-11-29 05:16:08 25 4
gpt4 key购买 nike

我正在使用 NLTokenizer 在 swift Playground 中显示 token 列表。

enter image description here

如何在标记之前显示索引号?

喜欢:

1.Introduction
2.to
3.Natural
4.Language
5.Processing

最佳答案

您可以尝试下面的代码片段。

let text = "Introduction to natural language processing"
let tokenizer = NLTokenizer(unit: .word)
tokenizer.string = text

for (index, range) in tokenizer.tokens(for: text.startIndex..<text.endIndex).enumerated() {
print("\(index + 1).\(text[range])")
}

关于ios - 在 Swift 中显示 NLTokenizer 的索引、标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59169308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com