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

The English-Chinese translation is incomplete. #20

Closed
detectRecog opened this issue Jan 27, 2024 · 2 comments
Closed

The English-Chinese translation is incomplete. #20

detectRecog opened this issue Jan 27, 2024 · 2 comments

Comments

@detectRecog
Copy link

haoranxu/ALMA-7B-R
Downloading shards: 100%|███████████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:01<00:00, 1.92it/s]
Loading checkpoint shards: 100%|████████████████████████████████████████████████████████████████████████████████████████████████████| 3/3 [00:28<00:00, 9.57s/it]
['Translate this from Chinese to English:\nChinese: 我爱机器翻译。\nEnglish: I love machine translation.']
['Translate this from English to Chinese:\nEnglish: The multi-modality large language model is designed for the big AGI industry.\nChinese:多模态大型语言模型是为大型人工智能行业设']
['Translate this from English to Chinese:\nEnglish: Chocolate Peanut Butter Protein Bars.\nChinese:巧克力芝士蛋白饼干。']

I write two random examples and want to convert the English sentences to Chinese:
The wired things happened that the output is always in-complete. (1-3 words are missing.)

The codes to reproduce are provided as follows:

name = "haoranxu/ALMA-7B-R"
print(name)
# Load base model and LoRA weights
model = AutoModelForCausalLM.from_pretrained(name, torch_dtype=torch.float16, device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(name, padding_side='left')

# Add the source sentence into the prompt template
prompts = ["Translate this from Chinese to English:\nChinese: 我爱机器翻译。\nEnglish:",
           "Translate this from English to Chinese:\nEnglish: The multi-modality large language model is designed for the big AGI industry.\nChinese:",
           "Translate this from English to Chinese:\nEnglish: Chocolate Peanut Butter Protein Bars.\nChinese:", # 巧克力花生酱蛋白棒
           ]

for prompt in prompts:
    input_ids = tokenizer(prompt, return_tensors="pt", padding=True, max_length=40, truncation=True).input_ids.cuda()
    # Translation
    with torch.no_grad():
        generated_ids = model.generate(input_ids=input_ids, num_beams=5, max_new_tokens=20, do_sample=True, temperature=0.6, top_p=0.9)
    outputs = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)
    print(outputs)
@fe1ixxu
Copy link
Owner

fe1ixxu commented Jan 27, 2024

Thanks for your interest!

Increasing the max_new_tokens from 20 to a larger number like 100 should fix issue of the incomplete translation.

@detectRecog
Copy link
Author

The problem is solved. Thanks! @fe1ixxu

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