我想要一天分享一點「LLM從底層堆疊的技術」,並且每篇文章長度控制在三分鐘以內,讓大家不會壓力太大,但是又能夠每天成長一點。
整理目前手上有的素材:
製作完 Inference 函數後,可以來做一個互動介面進行包裝:
!pip install ipywidgets
import ipywidgets as widgets
from IPython.display import display, clear_output
from transformers import RobertaTokenizer, RobertaForCausalLM
text_input = widgets.Textarea(description = 'Prompt:',
placeholder = 'Enter your prompt here...')
button = widgets.Button(description = 'Generate',
button_style = 'success')
output_text = widgets.Output(layout = {'border': '1px solid black', 'height': '100px'})
def on_button_clicked(b):
with output_text:
clear_output()
response = generate_response(text_input.value)
print(response)
button.on_click(on_button_clicked)
display(text_input, button, output_text)
介面如下:
輸入文字並產生輸出為: