kevanoullio / apples-to-apples-agent

Apples-to-Apples game with AI agent using various natural language processing and machine learning techniques.
GNU General Public License v3.0
0 stars 2 forks source link

Add a game_driver() prompt option or input argument for W2V or BERT embeddings #35

Open kevanoullio opened 3 months ago

kevanoullio commented 3 months ago

"bert-base-uncased" pretrained model from hugging face downloaded automatically from transformer library???

Example code:

from transformers import BertTokenizer, BertModel import torch

Load pre-trained model and tokenizer

tokenizer = BertTokenizer.from_pretrained('bert-base-uncased') model = BertModel.from_pretrained('bert-base-uncased')

Define the phrase

phrase = "reading a good book"

Tokenize the phrase

inputs = tokenizer(phrase, return_tensors='pt')

Generate embeddings

with torch.no_grad(): outputs = model(**inputs)

Get the embeddings for the [CLS] token (representing the entire phrase)

phrase_embedding = outputs.last_hidden_state[:, 0, :].squeeze()

print(phrase_embedding)