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

Why will there be blank between chinese characters? How to fix it? #75

Open
SupetZYK opened this issue Nov 8, 2023 · 1 comment
Open

Comments

@SupetZYK
Copy link

SupetZYK commented Nov 8, 2023

from transformers import BertTokenizer, BartForConditionalGeneration, Text2TextGenerationPipeline
tokenizer = BertTokenizer.from_pretrained("fnlp/bart-large-chinese")
model = BartForConditionalGeneration.from_pretrained("fnlp/bart-large-chinese")
text2text_generator = Text2TextGenerationPipeline(model, tokenizer)  
text2text_generator("北京是[MASK]的首都", max_length=50, do_sample=False)
    [{'generated_text': '北 京 是 中 华 人 民 共 和 国 的 首 都'}]

How to remove the blank between chinese characters?

@shivanraptor
Copy link

Just replace the space in the outputs with nothing by .replace(' ', ''). Easy.

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