Unverified Commit 4ec2cee0 authored by Reid's avatar Reid Committed by GitHub
Browse files

[Misc] improve example script output (#15528)


Signed-off-by: default avatarreidliu41 <reid201711@gmail.com>
Co-authored-by: default avatarreidliu41 <reid201711@gmail.com>
parent 99f536f8
...@@ -18,7 +18,10 @@ llm = LLM(model="facebook/opt-125m") ...@@ -18,7 +18,10 @@ llm = LLM(model="facebook/opt-125m")
# that contain the prompt, generated text, and other information. # that contain the prompt, generated text, and other information.
outputs = llm.generate(prompts, sampling_params) outputs = llm.generate(prompts, sampling_params)
# Print the outputs. # Print the outputs.
print("\nGenerated Outputs:\n" + "-" * 60)
for output in outputs: for output in outputs:
prompt = output.prompt prompt = output.prompt
generated_text = output.outputs[0].text generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}") print(f"Prompt: {prompt!r}")
\ No newline at end of file print(f"Output: {generated_text!r}")
print("-" * 60)
\ No newline at end of file
...@@ -27,12 +27,13 @@ def main(args: dict): ...@@ -27,12 +27,13 @@ def main(args: dict):
sampling_params.top_k = top_k sampling_params.top_k = top_k
def print_outputs(outputs): def print_outputs(outputs):
print("\nGenerated Outputs:\n" + "-" * 80)
for output in outputs: for output in outputs:
prompt = output.prompt prompt = output.prompt
generated_text = output.outputs[0].text generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}") print(f"Prompt: {prompt!r}\n")
print(f"Generated text: {generated_text!r}") print(f"Generated text: {generated_text!r}")
print("-" * 80) print("-" * 80)
print("=" * 80) print("=" * 80)
......
...@@ -23,12 +23,14 @@ def main(args: Namespace): ...@@ -23,12 +23,14 @@ def main(args: Namespace):
outputs = model.classify(prompts) outputs = model.classify(prompts)
# Print the outputs. # Print the outputs.
print("\nGenerated Outputs:\n" + "-" * 60)
for prompt, output in zip(prompts, outputs): for prompt, output in zip(prompts, outputs):
probs = output.outputs.probs probs = output.outputs.probs
probs_trimmed = ((str(probs[:16])[:-1] + probs_trimmed = ((str(probs[:16])[:-1] +
", ...]") if len(probs) > 16 else probs) ", ...]") if len(probs) > 16 else probs)
print(f"Prompt: {prompt!r} | " print(f"Prompt: {prompt!r} \n"
f"Class Probabilities: {probs_trimmed} (size={len(probs)})") f"Class Probabilities: {probs_trimmed} (size={len(probs)})")
print("-" * 60)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -23,12 +23,14 @@ def main(args: Namespace): ...@@ -23,12 +23,14 @@ def main(args: Namespace):
outputs = model.embed(prompts) outputs = model.embed(prompts)
# Print the outputs. # Print the outputs.
print("\nGenerated Outputs:\n" + "-" * 60)
for prompt, output in zip(prompts, outputs): for prompt, output in zip(prompts, outputs):
embeds = output.outputs.embedding embeds = output.outputs.embedding
embeds_trimmed = ((str(embeds[:16])[:-1] + embeds_trimmed = ((str(embeds[:16])[:-1] +
", ...]") if len(embeds) > 16 else embeds) ", ...]") if len(embeds) > 16 else embeds)
print(f"Prompt: {prompt!r} | " print(f"Prompt: {prompt!r} \n"
f"Embeddings: {embeds_trimmed} (size={len(embeds)})") f"Embeddings: {embeds_trimmed} (size={len(embeds)})")
print("-" * 60)
if __name__ == "__main__": if __name__ == "__main__":
......
...@@ -22,9 +22,11 @@ def main(args: Namespace): ...@@ -22,9 +22,11 @@ def main(args: Namespace):
outputs = model.score(text_1, texts_2) outputs = model.score(text_1, texts_2)
# Print the outputs. # Print the outputs.
print("\nGenerated Outputs:\n" + "-" * 60)
for text_2, output in zip(texts_2, outputs): for text_2, output in zip(texts_2, outputs):
score = output.outputs.score score = output.outputs.score
print(f"Pair: {[text_1, text_2]!r} | Score: {score}") print(f"Pair: {[text_1, text_2]!r} \nScore: {score}")
print("-" * 60)
if __name__ == "__main__": if __name__ == "__main__":
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment