#code
1 messages · Page 1 of 1 (latest)
I'm sorry, but your question is a bit unclear. Could you please provide more details? Are you asking for a specific Python code example related to OpenAI's tools or models?
For instance, if you're interested in how to use OpenAI's GPT models, here's an example of how to generate embeddings using OpenAI's tools, as extracted from the OpenAI Cookbook (https://cookbook.openai.com/examples/customizing_embeddings#0-imports):
# imports
from typing import List, Tuple # for type hints
import numpy as np # for manipulating arrays
import pandas as pd # for manipulating data in dataframes
import pickle # for saving the embeddings cache
import plotly.express as px # for plots
import random # for generating run IDs
from sklearn.model_selection import train_test_split # for splitting train & test data
import torch # for matrix optimization
from utils.embeddings_utils import get_embedding, cosine_similarity # for embeddings
# input parameters
embedding_cache_path = "data/snli_embedding_cache.pkl" # embeddings will be saved/loaded here
default_embedding_engine = "text-embedding-3-small"
num_pairs_to_embed = 1000 # 1000 is arbitrary
local_dataset_path = "data/snli_1.0_train_2k.csv" # download from: <https://nlp.stanford.edu/projects/snli/>
def process_input_data(df: pd.DataFrame) -> pd.DataFrame:
# you can customize this to preprocess your own dataset
# output should be a dataframe with 3 columns: text_1, text_2, label (1 for similar, -1 for dissimilar)
df["label"] = df["gold_label"]
df = df[df["label"].isin(["entailment"])]
df["label"] = df["label"].apply(lambda x: {"entailment": 1, "contradiction": -1}[x])
df = df.rename(columns={"sentence1": "text_1", "sentence2": "text_2"})
df = df[["text_1", "text_2", "label"]]
df = df.head(num_pairs_to_embed)
return df
This code is used to generate embeddings for a dataset and save them to a cache. It also includes a function to preprocess the dataset.
If you're looking for something different, please provide more details so I can give a more accurate response.
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@old sand kapa.ai is still learning and improving, please let us know how it did by reacting below