HelloImSteven/applescript-lines-annotated
Viewer • Updated • 510 • 32 • 1
How to use HelloImSteven/AppleScript-Summarizer with Transformers:
# Use a pipeline as a high-level helper
# Warning: Pipeline type "summarization" is no longer supported in transformers v5.
# You must load the model directly (see below) or downgrade to v4.x with:
# 'pip install "transformers<5.0.0'
from transformers import pipeline
pipe = pipeline("summarization", model="HelloImSteven/AppleScript-Summarizer") # Load model directly
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("HelloImSteven/AppleScript-Summarizer")
model = AutoModelForSeq2SeqLM.from_pretrained("HelloImSteven/AppleScript-Summarizer")# Load model directly
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("HelloImSteven/AppleScript-Summarizer")
model = AutoModelForSeq2SeqLM.from_pretrained("HelloImSteven/AppleScript-Summarizer")This model summarizes individual lines of AppleScript code and provides insights into their purpose and functionality. The model is trained on the applescript-lines-annotated dataset.
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, AutoConfig, pipeline
model_selector = "HelloImSteven/AppleScript-Summarizer"
tokenizer = AutoTokenizer.from_pretrained(model_selector)
model = AutoModelForSeq2SeqLM.from_pretrained(model_selector)
config = AutoConfig.from_pretrained(model_selector)
pipe = pipeline("summarization", model=model, config=config, tokenizer=tokenizer)
raw_code = [
"if myThing is 0 then set success to true",
"set numInputs to 5",
"tell application \"System Events\" to click button \"OK\" of window 1 of application process \"Finder\""
]
res = pipe(raw_code)
for i in range(len(res)):
print("\n\nInput: '" + raw_code[i] + "'")
print("\nSummary: " + res[i]["summary_text"] + '\n')
The model performs best when given adequate context, such as meaningful variable and handler names. For example, it will perform better when provided the input "on makeDirectory(dirPath)" than it will for "on makeDir(x)".
| Input | Output |
|---|---|
| on makeDirectory(dirPath) | This line of AppleScript code begins the definition of a handler named "makeDirectory". Based on its name, the handler is likely used to create a directory path from the path stored in the variable "dirPath". |
| open location "https://huggingface.co" | This is a line of AppleScript code that calls the built-in "open location" handler, providing the URL "https://huggingface.co" as a parameter. This is likely used to open a web browser. |
| do shell script "open -a 'Google Chrome'" | This is a line of AppleScript code that calls the "open -a" handler of the "Google Chrome" command, providing the output as a shell command. When executed, this line will open the Chrome web browser. |
This model is a work in progress. It is trained on a small dataset of annotated AppleScript lines, but that dataset will grow in time. For now, however, this leads to several limitations of the model:
do shell script command, it will be able to provide explanations of some shell scripts better than others. This is not an area of focus for this model, so do not expect significant improvements in future versions.
# Use a pipeline as a high-level helper # Warning: Pipeline type "summarization" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("summarization", model="HelloImSteven/AppleScript-Summarizer")