zhiqings's picture
Create README.md
d05a119 verified
|
raw
history blame
1.84 kB

Usage:

import torch
from transformers import AutoTokenizer, AutoModelForCausalLM

question_template = "# Question\n\n{question}\n\n# Solution\n\n"

model_name = "ScalableMath/llemma-7b-sft-prm800k-level-1to3-hf"
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")

tokenizer = AutoTokenizer.from_pretrained("EleutherAI/llemma_7b")

question = "Convert the point $(0,3)$ in rectangular coordinates to polar coordinates.  Enter your answer in the form $
(r,\\theta),$ where $r > 0$ and $0 \\le \\theta < 2 \\pi.$"
question = question_template.format(question=question)

input_tensor = torch.tensor([tokenizer.encode(question)])
outputs = model.generate(input_tensor.to(model.device), max_new_tokens=500)

result = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(result)

Example Results:

# Question

Convert the point $(0,3)$ in rectangular coordinates to polar coordinates.  Enter your answer in the form $(r,\theta),$ where $r > 0$ and $0 \le \theta < 2 \pi.$

# Solution

To convert from rectangular to polar coordinates, I need to use the formulas $r = \sqrt{x^2 + y^2}$ and $\theta = \tan^{-1}(y/x).$

In this case, $x = 0$ and $y = 3,$ so I can plug them into the formulas.

For $r,$ I get $r = \sqrt{0^2 + 3^2} = \sqrt{9} = 3.$

For $\theta,$ I get $\theta = \tan^{-1}(3/0).$

This is undefined, since the tangent function is not defined at $0.$

However, I can use the fact that the point $(0,3)$ lies on the positive $y$-axis, which has an angle of $\pi/2$ radians or $90^\circ.$

Therefore, I can choose any angle in the range $(0,\pi/2)$ as the value of $\theta.$

I will choose $\theta = \pi/2,$ since it is the simplest and most natural choice.

Therefore, the polar coordinates of the point $(0,3)$ are $(3,\pi/2).$

# Answer

(3,\pi/2)