Source code for wimarka.tasks.correction

from wimarka.utils.model import load_model

[docs] def generate_correction(src, tgt, errors, comments): model = load_model("correction") prompt = ( f"""You are correcting a translation. You are given the source and target translation. The sentence has a tag at the start indicating the language. The language tags are: [EN] - English [CEB] - Cebuano [ILO] - Ilocano [TGL] - Tagalog You are also given the target translation but with each error wrapped with tags. The following tags are: [MI_ST] - Minor Syntactic Error [MI_SE] - Minor Semantic Error [MA_ST] - Major Syntactic Error [MA_SE] - Major Semantic Error You will also be given an explanation for each error. The explanations are indexed to the order of the errors. Respond with the corrected translation. If there are no errors wrapped and the explanation just says "The translation has conveyed the meaning with well-structured syntax", respond with the original translation. Example: Source: [EN] I am your mother, Jerry! Target: [TGL] Lolo niya ako, Jerry. Errors: [TGL] [MA_SE]Lolo niya[/MA_SE] ako, Jerry [MI_ST] . [/MI_ST] Explanation: [MA_SE] “Lolo niya” refers to the grandfather of a third person, while the source refers to the mother of the person the speaker is talking to. [/MA_SE] [MI_ST] ! should be used instead of . to be inline with the expression [/MI_ST] Correction: [TGL] Nanay mo ako, Jerry! Machine Translation: Source: {src} Target: {tgt} Errors: {errors} Explanation: {comments} Correction: """ ) messages = [ {"role": "user", "content": prompt} ] response = model.create_chat_completion( messages=messages, stop=["<eos>"], ) generated_text = response["choices"][0]["message"]["content"] return generated_text