import torch from transformers import M2M100ForConditionalGeneration, M2M100Tokenizer # 直接选择 GPU 设备 device = torch.device("cuda") # 替换为实际的模型和分词器路径 model_path = "/opt/m2m100_1.2B/model" tokenizer_path = "/opt/m2m100_1.2B/tokenizer" # 加载模型和分词器 model = M2M100ForConditionalGeneration.from_pretrained(model_path).to(device) # 将模型移动到 GPU tokenizer = M2M100Tokenizer.from_pretrained(tokenizer_path) # 按句子切分的函数 def split_text(text): sentences = text.replace(".", ".\n").replace("!", "!\n").replace("?", "?\n").splitlines() return [s.strip() for s in sentences if s.strip()] # 翻译函数 def translate_text(text_chunk, src_lang, tgt_lang): tokenizer.src_lang = src_lang # 设置源语言 encoded_input = tokenizer(text_chunk, return_tensors="pt", truncation=True, max_length=900) # 将输入张量移动到 GPU encoded_input = {k: v.to(device) for k, v in encoded_input.items()} # 生成翻译 generated_tokens = model.generate(**encoded_input, forced_bos_token_id=tokenizer.get_lang_id(tgt_lang)) # 设置目标语言 translated_text = tokenizer.decode(generated_tokens[0], skip_special_tokens=True) return translated_text # 示例文本(替换为实际文本) text = 'The National Transportation Safety Board is issuing “urgent safety recommendations” for some Boeing 737s—including the embattled 737 MAX line— warning that critical flight controls could jam.The independent investigative a gency is issuing the warning that an actuator attached to the rudder on some 737 NG and 737 MAX airplanes could fail. The move comes after the NTSB investigated a February incident where the pilots of a United Airlines MAX 8 landi ng in Newark reported their rudder pedals “stuck” in the neutral position.The warning is the latest black eye for Boeing. The company has seen a string of ugly headlines this year, from a mid-air blowout of a door plug in January to a strike by 33,000 workers that started just this month.“Boeing’s 737 flight manual instructs pilots confronted with a jammed or restricted rudder to ‘overpower the jammed or restricted system (using) maximum force, including a combined effort of both pilots,’” the NTSB said in a news release.“The NTSB expressed concern that this amount of force applied during landing or rollout could result in a large input to the rudder pedals and a sudden, large, and undesired rudder deflection that could unintentionally cause loss of control or departure from a runway,” the statement said.The NTSB is recommending that Boeing come up with an alternative solution and warn pilots about the issu e.In a statement, the FAA says it “monitoring the situation closely” and will “convene a corrective action review board based upon the NTSB’s interim recommendations and determine next steps” on Friday. CNN has reached out to Boei ng for comment.The FAA says United Airlines is the only US airline with 737s that use the components in question and that they are no longer being used.A range of problemsIn the last five years, Boeing has suffered a myriad of pro blems, some tragic and many embarrassing. Most of them have proven financially devastating.Two fatal crashes of its 737 Max, one in October 2018 and the other in March 2019, killed 346 people and led to a 20-month grounding of Boe ing’s best-selling plane and a halt in deliveries to fix a design flaw tied to the crashes.

CNNs Pete Muntean looks at results just unveiled from an FAA audit launched in the wake of the 737 Max door plug blowout incident.

FAA: Boeing workers pressured to put speed over quality02:46 - Source: CNNBoeing then faced a series of other questions about the quality and safety of its planes. That scrutiny grew after a door plug blew off a 737 Max operated b y Alaska Airlines shortly after takeoff on January 5. Although no one was killed or seriously injured, the incident sparked numerous federal investigations, one of which revealed the plane had left a Boeing factory without the fou r bolts needed to hold the door plug in place.Since then, Boeing has agreed to plead guilty to federal criminal charges of deceiving the Federal Aviation Administration during the initial investigation of the Max. As part of its a greement with the US Justice Department, the company will have to operate under the supervision of a court-appointed monitor.This is a developing story and will be updated.CNN’s Chris Isidore contributed reporting.' # 1. 按句子切分 text_chunks = split_text(text) # 2. 逐段翻译 translated_chunks = [translate_text(chunk, src_lang="en", tgt_lang="zh") for chunk in text_chunks] # 3. 合并翻译结果 translated_text = " ".join(translated_chunks) # 输出结果 print(translated_text)