在数字通信时代,文本的清晰度和可读性至关重要。无论是转录口语、处理原始文本数据还是改进用户生成的内容,标点符号在传达预期信息方面都起着至关重要的作用。但是,手动编辑文本以添加标点符号可能非常耗时且容易出错。这就是人工智能 (AI) 发挥作用的地方,它提供了一种强大的解决方案,可以自动将标点符号插入句子中。
目前,利用大模型的能力,完全可以胜任添加标点符号的工作,不需要其它特别的处理程序。
参考代码
from openai import OpenAI
class PunctuationCorrector:
def __init__(self, api_key):
self.client = OpenAI(api_key=api_key)
def add_punctuation(self, text):
response = self.client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "Correct the punctuation of the following text:"},
{"role": "user", "content": text}])
return response.choices[0].message.content if response.choices else "No response generated."
应用
if __name__ == "__main__":
api_key = "your_api_key_here" # Replace with your actual OpenAI API key
corrector = PunctuationCorrector(api_key)
original_text = "Lord but Im glad to see you again Phil" # Replace with your Sentence/Paragraph
punctuated_text = corrector.add_punctuation(original_text)
print("Original:", original_text)
print("Punctuated:", punctuated_text)