昨天的版本已經能讓AI同時做出摘要、翻譯與回答問題,而且使用者也可以自己輸入文章與問題,算是我這整個小專案正式成型的一天。
不過做到這裡,我發現雖然功能能跑,但如果別人想用我的程式,好像還是會有點迷茫,不知道哪一步該先做、哪裡要放token。
所以今天,我要來寫一份正式的使用教學!
專案介紹
這是一個最小可運作的AI問答機器人。
它可以做到三件事:
執行環境
這個專案在Google Colab上運行,需要先安裝幾個基本套件:
!pip -q install transformers==4.44.2 accelerate huggingface_hub regex
如果有Hugging Face的帳號,記得先到左側的Secrets設定,加入你的Token。
程式架構
整份程式可以分成四個主要部分:
user_text = input("請輸入一段文章:\n")
question = input("\n請輸入你的問題:\n")
print("\n=== 三句摘要(英文) ===")
print(gen_summary_3sent(user_text))
print("\n=== 原文翻譯(繁中) ===")
print(translate_to_zh(user_text))
print("\n=== 問題 ===")
print(question)
print("\n=== QA 答案 ===")
print(answer_question(user_text, question))
實際執行結果
我輸入了這段文字:
Artificial Intelligence is transforming the field of medicine.
It can help in diagnosing diseases, analyzing medical images,
and even assisting in drug discovery.
This progress is driven by advances in machine learning and deep learning.
However, there are challenges such as data privacy and security.
然後問:
What are some challenges mentioned in using AI for medicine?
執行結果如下:
可以看到:
這份教學的目的,就是讓別人也能輕鬆跑起這個小專案。
從一開始需要修改code,到現在只要輸入文章與問題就能得到完整結果,
我覺得這樣的體驗才是真的AI 工具該有的樣子。