Views
No views yet
1from transformers import AutoTokenizer, AutoModel
2import torch
3
4# Define the model name (either your custom model or a pre-trained model from Hugging Face)
5model_name = "ortaymed/bert_assurance" # Replace with your model name or path
6
7# Your Hugging Face token
8hf_token = "your-huggingface-token" # Replace with your actual Hugging Face token
9
10# Load the tokenizer and model with the token
11tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=hf_token)
12model = AutoModel.from_pretrained(model_name, use_auth_token=hf_token)
13
14# Sample input text
15input_text = "Your sample input text goes here."
16
17# Tokenize the input text
18inputs = tokenizer(input_text, return_tensors="pt")
19
20# Get embeddings
21with torch.no_grad():
22 outputs = model(**inputs)
23
24# Get the embeddings from the last hidden state
25embeddings = outputs.last_hidden_state
26
27print(embeddings)