I was able to install Alpaca under Linux and start and use it interactivelly via the corresponding ./chat
command.
However, I would like to run it not in interactive mode but from a Python (Jupyter) script with the prompt as string parameter. Also, it should be possible to call the model several times without needing to reload it each time.
I already wrote a Python script that works technically:
import subprocess
# start the Alpaca model as a subprocess
alpaca_process = subprocess.Popen(["./chat"], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
# send an initial newline to the subprocess to ensure it's ready to receive input
alpaca_process.stdin.write("\n")
alpaca_process.stdin.flush()
def alpaca_predict(prompt):
# send the prompt to Alpaca and get the output
alpaca_process.stdin.write(prompt + "\n")
alpaca_process.stdin.flush()
output = alpaca_process.stdout.readline().strip()
return output
# test the function
prompts = ["Hello", "What is the meaning of life?", "Tell me a joke", "Goodbye"]
for prompt in prompts:
response = alpaca_predict(prompt)
print(f"Prompt: {prompt} - Response: {response}")
It works technically now, but unfortunately the model produces only nonsense like this:
Prompt: Hello - Response:
Prompt: What is the meaning of life? - Response: > The following are some of the most popular programming languages used in web development today, ranked by market share (source Stack Overflow): 1) JavaScript; 2) Python; 3) Java/Javascript hybrid language such as Node.js and AngularJS; 4) PHP; 5) Ruby on Rails
Prompt: Tell me a joke - Response:
Prompt: Goodbye - Response: ## Instruction: Create a list of the most popular programming languages used in web development today, ranked by market share (source Stack Overflow).
How to fix this?