Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

你好 请问bpes代表什么意思? #17

Open
ShaoZhangHao opened this issue Nov 26, 2023 · 1 comment
Open

你好 请问bpes代表什么意思? #17

ShaoZhangHao opened this issue Nov 26, 2023 · 1 comment

Comments

@ShaoZhangHao
Copy link

bpes = [self.cls]
indexes = [0]
spans = []
ins_lst = []
new_ent_str = Counter()
for _raw_words, _raw_ents in zip(raw_sents, raw_entss):
_indexes = []
_bpes = []
for s, e, t in _raw_ents:
new_ent_str[''.join(_raw_words[s:e+1])] += 1

            for idx, word in enumerate(_raw_words, start=0):
                if word in word2bpes:
                    __bpes = word2bpes[word]
                else:
                    __bpes = self.tokenizer.encode(' '+word if self.add_prefix_space else word,
                                                   add_special_tokens=False)
                    word2bpes[word] = __bpes
                _indexes.extend([idx]*len(__bpes))
                _bpes.extend(__bpes)
            next_word_idx = indexes[-1]+1
            if len(bpes) + len(_bpes) <= self.max_len:
                bpes = bpes + _bpes
                indexes += [i + next_word_idx for i in _indexes]
                spans += [(s+next_word_idx-1, e+next_word_idx-1, label2idx.get(t), ) for s, e, t in _raw_ents]
            else:
                new_ins = get_new_ins(bpes, spans, indexes)
                ins_lst.append(new_ins)
                indexes = [0] + [i + 1 for i in _indexes]
                spans = [(s, e, label2idx.get(t), ) for s, e, t in _raw_ents]
                bpes = [self.cls] + _bpes
        if bpes:
            ins_lst.append(get_new_ins(bpes, spans, indexes))

关于论文中这一部分的代码我没有理解是想处理什么

@yhcc
Copy link
Owner

yhcc commented May 20, 2024

bpes是tokenize好的内容。等同于text中的word被依次tokenize,然后被依次append到bpes这个里面。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants