Download Implement Terminology using Python program from avra121/xyz: direct link, hf CLI and curl.
- Browser
- Download file 721 Bytes
-
https://huggingface.co/spaces/avra121/xyz/resolve/main/Implement%20Terminology%20using%20Python%20program
- Command line
-
hf download 'hf://spaces/avra121/xyz/Implement Terminology using Python program'
-
curl -L -o 'Implement Terminology using Python program' https://huggingface.co/spaces/avra121/xyz/resolve/main/Implement%20Terminology%20using%20Python%20program
721 Bytes
| import torch | |
| from transformers import AutoTokenizer, AutoModelForCausalLM | |
| model_name = "gpt2" | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained(model_name) | |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | |
| model = model.to(device) | |
| prompt = "Artificial Intelligence is" | |
| inputs = tokenizer(prompt, return_tensors="pt").to(device) | |
| output = model.generate( | |
| inputs["input_ids"], | |
| attention_mask=inputs["attention_mask"], | |
| max_length=30, | |
| temperature=0.7, | |
| do_sample=True, | |
| pad_token_id=tokenizer.eos_token_id | |
| ) | |
| generated_text = tokenizer.decode(output[0], skip_special_tokens=True) | |
| print("Generated Text:\n") | |
| print(generated_text) |