এম্বেডিংয়ের সাথে অসঙ্গতি সনাক্তকরণ

ai.google.dev এ দেখুন Google Colab-এ চালান GitHub-এ উৎস দেখুন

ওভারভিউ

এই টিউটোরিয়ালটি দেখায় কিভাবে আপনার ডেটাসেটে সম্ভাব্য বহিরাগত শনাক্ত করতে Gemini API থেকে এমবেডিং ব্যবহার করতে হয়। আপনি t-SNE ব্যবহার করে 20 টি নিউজগ্রুপ ডেটাসেটের একটি উপসেট কল্পনা করবেন এবং প্রতিটি শ্রেণীবদ্ধ ক্লাস্টারের কেন্দ্রীয় বিন্দুর একটি নির্দিষ্ট ব্যাসার্ধের বাইরে আউটলায়ার্স সনাক্ত করবেন।

Gemini API থেকে জেনারেট করা এম্বেডিংয়ের সাথে শুরু করার বিষয়ে আরও তথ্যের জন্য, Python quickstart দেখুন।

পূর্বশর্ত

আপনি Google Colab-এ এই কুইকস্টার্ট চালাতে পারেন।

আপনার নিজের বিকাশের পরিবেশে এই দ্রুত সূচনাটি সম্পূর্ণ করতে, নিশ্চিত করুন যে আপনার পরিবেশ নিম্নলিখিত প্রয়োজনীয়তাগুলি পূরণ করে:

  • Python 3.9+
  • নোটবুক চালানোর জন্য jupyter একটি ইনস্টলেশন।

সেটআপ

প্রথমে, জেমিনি API পাইথন লাইব্রেরি ডাউনলোড এবং ইনস্টল করুন।

pip install -U -q google.generativeai
import re
import tqdm
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

import google.generativeai as genai
import google.ai.generativelanguage as glm

# Used to securely store your API key
from google.colab import userdata

from sklearn.datasets import fetch_20newsgroups
from sklearn.manifold import TSNE

একটি API কী ধরুন

আপনি Gemini API ব্যবহার করার আগে, আপনাকে প্রথমে একটি API কী পেতে হবে। যদি আপনার কাছে ইতিমধ্যে একটি না থাকে তবে Google AI স্টুডিওতে এক ক্লিকে একটি কী তৈরি করুন৷

একটি API কী পান

Colab-এ, বাঁদিকের প্যানেলে "🔑"-এর নিচে সিক্রেট ম্যানেজারের কী যোগ করুন। এটিকে API_KEY নাম দিন।

একবার আপনার কাছে API কী হয়ে গেলে, এটি SDK-এ পাস করুন। আপনি এটি দুটি উপায়ে করতে পারেন:

  • কীটি GOOGLE_API_KEY এনভায়রনমেন্ট ভেরিয়েবলে রাখুন (SDK স্বয়ংক্রিয়ভাবে সেখান থেকে তুলে নেবে)।
  • genai.configure(api_key=...) এ কী পাস করুন
# Or use `os.getenv('API_KEY')` to fetch an environment variable.
API_KEY=userdata.get('API_KEY')

genai.configure(api_key=API_KEY)
for m in genai.list_models():
  if 'embedContent' in m.supported_generation_methods:
    print(m.name)
models/embedding-001
models/embedding-001

ডেটাসেট প্রস্তুত করুন

20টি নিউজগ্রুপ টেক্সট ডেটাসেটে 20টি বিষয়ের উপর 18,000টি নিউজগ্রুপ পোস্ট রয়েছে যা প্রশিক্ষণ এবং পরীক্ষার সেটে বিভক্ত। প্রশিক্ষণ এবং পরীক্ষার ডেটাসেটের মধ্যে বিভাজন একটি নির্দিষ্ট তারিখের আগে এবং পরে পোস্ট করা বার্তাগুলির উপর ভিত্তি করে। এই টিউটোরিয়াল প্রশিক্ষণ উপসেট ব্যবহার করে।

newsgroups_train = fetch_20newsgroups(subset='train')

# View list of class names for dataset
newsgroups_train.target_names
['alt.atheism',
 'comp.graphics',
 'comp.os.ms-windows.misc',
 'comp.sys.ibm.pc.hardware',
 'comp.sys.mac.hardware',
 'comp.windows.x',
 'misc.forsale',
 'rec.autos',
 'rec.motorcycles',
 'rec.sport.baseball',
 'rec.sport.hockey',
 'sci.crypt',
 'sci.electronics',
 'sci.med',
 'sci.space',
 'soc.religion.christian',
 'talk.politics.guns',
 'talk.politics.mideast',
 'talk.politics.misc',
 'talk.religion.misc']

এখানে প্রশিক্ষণ সেট প্রথম উদাহরণ.

idx = newsgroups_train.data[0].index('Lines')
print(newsgroups_train.data[0][idx:])
Lines: 15

 I was wondering if anyone out there could enlighten me on this car I saw
the other day. It was a 2-door sports car, looked to be from the late 60s/
early 70s. It was called a Bricklin. The doors were really small. In addition,
the front bumper was separate from the rest of the body. This is 
all I know. If anyone can tellme a model name, engine specs, years
of production, where this car is made, history, or whatever info you
have on this funky looking car, please e-mail.

Thanks,

- IL
   ---- brought to you by your neighborhood Lerxst ----
# Apply functions to remove names, emails, and extraneous words from data points in newsgroups.data
newsgroups_train.data = [re.sub(r'[\w\.-]+@[\w\.-]+', '', d) for d in newsgroups_train.data] # Remove email
newsgroups_train.data = [re.sub(r"\([^()]*\)", "", d) for d in newsgroups_train.data] # Remove names
newsgroups_train.data = [d.replace("From: ", "") for d in newsgroups_train.data] # Remove "From: "
newsgroups_train.data = [d.replace("\nSubject: ", "") for d in newsgroups_train.data] # Remove "\nSubject: "

# Cut off each text entry after 5,000 characters
newsgroups_train.data = [d[0:5000] if len(d) > 5000 else d for d in newsgroups_train.data]
# Put training points into a dataframe
df_train = pd.DataFrame(newsgroups_train.data, columns=['Text'])
df_train['Label'] = newsgroups_train.target
# Match label to target name index
df_train['Class Name'] = df_train['Label'].map(newsgroups_train.target_names.__getitem__)

df_train

এরপর, প্রশিক্ষণ ডেটাসেটে 150টি ডেটা পয়েন্ট নিয়ে এবং কয়েকটি বিভাগ বেছে নিয়ে কিছু ডেটার নমুনা নিন। এই টিউটোরিয়ালটি বিজ্ঞান বিভাগ ব্যবহার করে।

# Take a sample of each label category from df_train
SAMPLE_SIZE = 150
df_train = (df_train.groupby('Label', as_index = False)
                    .apply(lambda x: x.sample(SAMPLE_SIZE))
                    .reset_index(drop=True))

# Choose categories about science
df_train = df_train[df_train['Class Name'].str.contains('sci')]

# Reset the index
df_train = df_train.reset_index()
df_train
df_train['Class Name'].value_counts()
sci.crypt          150
sci.electronics    150
sci.med            150
sci.space          150
Name: Class Name, dtype: int64

এমবেডিং তৈরি করুন

এই বিভাগে, আপনি জেমিনি API থেকে এমবেডিংগুলি ব্যবহার করে ডেটাফ্রেমের বিভিন্ন পাঠ্যের জন্য এমবেডিংগুলি কীভাবে তৈরি করবেন তা দেখতে পাবেন।

মডেল এমবেডিং-001 সহ এম্বেডিং-এ API পরিবর্তন হয়

নতুন এম্বেডিং মডেলের জন্য, এম্বেডিং-001, একটি নতুন টাস্ক টাইপ প্যারামিটার এবং ঐচ্ছিক শিরোনাম রয়েছে (শুধুমাত্র task_type= RETRIEVAL_DOCUMENT এর সাথে বৈধ)।

এই নতুন প্যারামিটারগুলি শুধুমাত্র নতুন এমবেডিং মডেলগুলিতে প্রযোজ্য৷ টাস্কের ধরনগুলি হল:

টাস্ক টাইপ বর্ণনা
RETRIEVAL_QUERY প্রদত্ত টেক্সট একটি অনুসন্ধান/পুনরুদ্ধার সেটিং একটি ক্যোয়ারী নির্দিষ্ট করে.
RETRIEVAL_DOCUMENT প্রদত্ত পাঠ্যটি একটি অনুসন্ধান/পুনরুদ্ধার সেটিং এর একটি নথি নির্দিষ্ট করে৷
SEMANTIC_SIMILARITY প্রদত্ত টেক্সট শব্দার্থিক টেক্সচুয়াল সাদৃশ্য (STS) এর জন্য ব্যবহার করা হবে তা নির্দিষ্ট করে।
শ্রেণীবিভাগ নির্দিষ্ট করে যে এমবেডিংগুলি শ্রেণীবিভাগের জন্য ব্যবহার করা হবে৷
ক্লাস্টারিং নির্দিষ্ট করে যে এমবেডিংগুলি ক্লাস্টারিংয়ের জন্য ব্যবহার করা হবে৷
from tqdm.auto import tqdm
tqdm.pandas()

from google.api_core import retry

def make_embed_text_fn(model):

  @retry.Retry(timeout=300.0)
  def embed_fn(text: str) -> list[float]:
    # Set the task_type to CLUSTERING.
    embedding = genai.embed_content(model=model,
                                    content=text,
                                    task_type="clustering")['embedding']
    return np.array(embedding)

  return embed_fn

def create_embeddings(df):
  model = 'models/embedding-001'
  df['Embeddings'] = df['Text'].progress_apply(make_embed_text_fn(model))
  return df

df_train = create_embeddings(df_train)
df_train.drop('index', axis=1, inplace=True)
0%|          | 0/600 [00:00<?, ?it/s]

মাত্রিকতা হ্রাস

ডকুমেন্ট এমবেডিং ভেক্টরের মাত্রা হল 768৷ এমবেড করা নথিগুলিকে কীভাবে একত্রিত করা হয়েছে তা কল্পনা করার জন্য, আপনাকে মাত্রিকতা হ্রাস প্রয়োগ করতে হবে কারণ আপনি কেবলমাত্র 2D বা 3D স্পেসে এমবেডিংগুলিকে কল্পনা করতে পারেন৷ প্রাসঙ্গিকভাবে অনুরূপ নথিগুলি মহাকাশে একত্রে কাছাকাছি হওয়া উচিত নথিগুলির বিপরীতে যা অনুরূপ নয়।

len(df_train['Embeddings'][0])
768
# Convert df_train['Embeddings'] Pandas series to a np.array of float32
X = np.array(df_train['Embeddings'].to_list(), dtype=np.float32)
X.shape
(600, 768)

ডাইমেনশ্যালিটি রিডাকশন করার জন্য আপনি টি-ডিস্ট্রিবিউটেড স্টোকাস্টিক নেবার এম্বেডিং (t-SNE) পদ্ধতি প্রয়োগ করবেন। ক্লাস্টারগুলি সংরক্ষণ করার সময় এই কৌশলটি মাত্রার সংখ্যা হ্রাস করে (বিন্দু যেগুলি একত্রে কাছাকাছি থাকে তারা একসাথে থাকে)। আসল ডেটার জন্য, মডেলটি এমন একটি ডিস্ট্রিবিউশন তৈরি করার চেষ্টা করে যার উপর অন্যান্য ডেটা পয়েন্টগুলি "প্রতিবেশী" (যেমন, তারা একই অর্থ ভাগ করে)। এটি তারপর একটি উদ্দেশ্য ফাংশন অপ্টিমাইজ করে ভিজ্যুয়ালাইজেশনে একটি অনুরূপ বিতরণ রাখতে।

tsne = TSNE(random_state=0, n_iter=1000)
tsne_results = tsne.fit_transform(X)
df_tsne = pd.DataFrame(tsne_results, columns=['TSNE1', 'TSNE2'])
df_tsne['Class Name'] = df_train['Class Name'] # Add labels column from df_train to df_tsne
df_tsne
fig, ax = plt.subplots(figsize=(8,6)) # Set figsize
sns.set_style('darkgrid', {"grid.color": ".6", "grid.linestyle": ":"})
sns.scatterplot(data=df_tsne, x='TSNE1', y='TSNE2', hue='Class Name', palette='Set2')
sns.move_legend(ax, "upper left", bbox_to_anchor=(1, 1))
plt.title('Scatter plot of news using t-SNE')
plt.xlabel('TSNE1')
plt.ylabel('TSNE2');

png

বহিরাগত সনাক্তকরণ

কোন পয়েন্টগুলি অসামঞ্জস্যপূর্ণ তা নির্ধারণ করতে, আপনি নির্ধারণ করবেন কোন পয়েন্টগুলি ইনলাইয়ার এবং আউটলিয়ার। ক্লাস্টারের কেন্দ্রের প্রতিনিধিত্ব করে এমন সেন্ট্রয়েড বা অবস্থান খুঁজে বের করে শুরু করুন এবং বিন্দুগুলি নির্ণয় করতে দূরত্ব ব্যবহার করুন।

প্রতিটি বিভাগের সেন্ট্রোয়েড পেয়ে শুরু করুন।

def get_centroids(df_tsne):
  # Get the centroid of each cluster
  centroids = df_tsne.groupby('Class Name').mean()
  return centroids

centroids = get_centroids(df_tsne)
centroids
def get_embedding_centroids(df):
  emb_centroids = dict()
  grouped = df.groupby('Class Name')
  for c in grouped.groups:
    sub_df = grouped.get_group(c)
    # Get the centroid value of dimension 768
    emb_centroids[c] = np.mean(sub_df['Embeddings'], axis=0)

  return emb_centroids
emb_c = get_embedding_centroids(df_train)

বাকি পয়েন্টের বিপরীতে আপনি পাওয়া প্রতিটি সেন্ট্রয়েড প্লট করুন।

# Plot the centroids against the cluster
fig, ax = plt.subplots(figsize=(8,6)) # Set figsize
sns.set_style('darkgrid', {"grid.color": ".6", "grid.linestyle": ":"})
sns.scatterplot(data=df_tsne, x='TSNE1', y='TSNE2', hue='Class Name', palette='Set2');
sns.scatterplot(data=centroids, x='TSNE1', y='TSNE2', color="black", marker='X', s=100, label='Centroids')
sns.move_legend(ax, "upper left", bbox_to_anchor=(1, 1))
plt.title('Scatter plot of news using t-SNE with centroids')
plt.xlabel('TSNE1')
plt.ylabel('TSNE2');

png

একটি ব্যাসার্ধ চয়ন করুন. এই বিভাগের সেন্ট্রয়েড থেকে এই সীমার বাইরে যে কোনও কিছুকে আউটলায়ার হিসাবে বিবেচনা করা হয়।

def calculate_euclidean_distance(p1, p2):
  return np.sqrt(np.sum(np.square(p1 - p2)))

def detect_outlier(df, emb_centroids, radius):
  for idx, row in df.iterrows():
    class_name = row['Class Name'] # Get class name of row
    # Compare centroid distances
    dist = calculate_euclidean_distance(row['Embeddings'],
                                        emb_centroids[class_name])
    df.at[idx, 'Outlier'] = dist > radius

  return len(df[df['Outlier'] == True])
range_ = np.arange(0.3, 0.75, 0.02).round(decimals=2).tolist()
num_outliers = []
for i in range_:
  num_outliers.append(detect_outlier(df_train, emb_c, i))
# Plot range_ and num_outliers
fig = plt.figure(figsize = (14, 8))
plt.rcParams.update({'font.size': 12})
plt.bar(list(map(str, range_)), num_outliers)
plt.title("Number of outliers vs. distance of points from centroid")
plt.xlabel("Distance")
plt.ylabel("Number of outliers")
for i in range(len(range_)):
  plt.text(i, num_outliers[i], num_outliers[i], ha = 'center')

plt.show()

png

আপনি আপনার অ্যানোমালি ডিটেক্টরটি কতটা সংবেদনশীল হতে চান তার উপর নির্ভর করে, আপনি কোন ব্যাসার্ধটি ব্যবহার করতে চান তা চয়ন করতে পারেন। এখন, 0.62 ব্যবহার করা হয়, কিন্তু আপনি এই মান পরিবর্তন করতে পারেন।

# View the points that are outliers
RADIUS = 0.62
detect_outlier(df_train, emb_c, RADIUS)
df_outliers = df_train[df_train['Outlier'] == True]
df_outliers.head()
# Use the index to map the outlier points back to the projected TSNE points
outliers_projected = df_tsne.loc[df_outliers['Outlier'].index]

আউটলার প্লট করুন এবং একটি স্বচ্ছ লাল রঙ ব্যবহার করে তাদের চিহ্নিত করুন।

fig, ax = plt.subplots(figsize=(8,6)) # Set figsize
plt.rcParams.update({'font.size': 10})
sns.set_style('darkgrid', {"grid.color": ".6", "grid.linestyle": ":"})
sns.scatterplot(data=df_tsne, x='TSNE1', y='TSNE2', hue='Class Name', palette='Set2');
sns.scatterplot(data=centroids, x='TSNE1', y='TSNE2', color="black", marker='X', s=100, label='Centroids')
# Draw a red circle around the outliers
sns.scatterplot(data=outliers_projected, x='TSNE1', y='TSNE2', color='red', marker='o', alpha=0.5, s=90, label='Outliers')
sns.move_legend(ax, "upper left", bbox_to_anchor=(1, 1))
plt.title('Scatter plot of news with outliers projected with t-SNE')
plt.xlabel('TSNE1')
plt.ylabel('TSNE2');

png

প্রতিটি বিভাগে আউটলায়ারগুলি কেমন হতে পারে তার কয়েকটি উদাহরণ প্রিন্ট করতে ডেটাফেমের সূচক মান ব্যবহার করুন। এখানে, প্রতিটি বিভাগ থেকে প্রথম ডেটা পয়েন্ট প্রিন্ট করা হয়। বহির্মুখী, বা অসামঞ্জস্য হিসাবে গণ্য করা হয় এমন ডেটা দেখতে প্রতিটি বিভাগের অন্যান্য পয়েন্টগুলি অন্বেষণ করুন।

sci_crypt_outliers = df_outliers[df_outliers['Class Name'] == 'sci.crypt']
print(sci_crypt_outliers['Text'].iloc[0])
Re: Source of random bits on a Unix workstation
Lines: 44
Nntp-Posting-Host: sandstorm

>>For your application, what you can do is to encrypt the real-time clock
>>value with a secret key.

Well, almost.... If I only had to solve the problem for myself, and were
willing to have to type in a second password  whenever I
logged in, it could work. However, I'm trying to create a solution that
anyone can use, and which, once installed, is just as effortless to start up
as the non-solution of just using xhost to control access. I've got
religeous problems with storing secret keys on multiuser computers.

>For a good discussion of cryptographically "good" random number
>generators, check out the draft-ietf-security-randomness-00.txt
>Internet Draft, available at your local friendly internet drafts
>repository.

Thanks for the pointer! It was good reading, and I liked the idea of using
several unrelated sources with a strong mixing function. However, unless I
missed something, the only source they suggested 
that seems available, and unguessable by an intruder, when a Unix is
fresh-booted, is I/O buffers related to network traffic. I believe my
solution basically uses that strategy, without requiring me to reach into
the kernel.

>A reasonably source of randomness is the output of a cryptographic
>hash function , when fed with a large amount of
>more-or-less random data. For example, running MD5 on /dev/mem is a
>slow, but random enough, source of random bits; there are bound to be
>128 bits of entropy in the tens  of megabytes of data in
>a modern workstation's memory, as a fair amount of them are system
>timers, i/o buffers, etc.

I heard about this solution, and it sounded good. Then I heard that folks
were experiencing times of 30-60 seconds to run this, on
reasonably-configured workstations. I'm not willing to add that much delay
to someone's login process. My approach  takes
a second or two to run. I'm considering writing the be-all and end-all of
solutions, that launches the MD5, and simultaneously tries to suck bits off
the net, and if the net should be sitting __SO__ idle that it can't get 10K
after compression before MD5 finishes, use the MD5. This way I could have
guaranteed good bits, and a deterministic upper bound on login time, and
still have the common case of login take only a couple of extra seconds.

-Bennett
sci_elec_outliers = df_outliers[df_outliers['Class Name'] == 'sci.electronics']
print(sci_elec_outliers['Text'].iloc[0])
Re: Laser vs Bubblejet?
Reply-To: 
Distribution: world
X-Mailer: cppnews \\(Revision: 1.20 \\)
Organization: null
Lines: 53

Here is a different viewpoint.

> FYI:  The actual horizontal dot placement resoution of an HP
> deskjet is 1/600th inch.  The electronics and dynamics of the ink
> cartridge, however, limit you to generating dots at 300 per inch.
> On almost any paper, the ink wicks more than 1/300th inch anyway.
> 
> The method of depositing and fusing toner of a laster printer
> results in much less spread than ink drop technology.

In practice there is little difference in quality but more care is needed 
with inkjet because smudges etc. can happen.

> It doesn't take much investigation to see that the mechanical and
> electronic complement of a laser printer is more complex than
> inexpensive ink jet printers.  Recall also that laser printers
> offer a much higher throughput:  10 ppm for a laser versus about 1
> ppm for an ink jet printer.

A cheap laser printer does not manage that sort of throughput and on top of 
that how long does the _first_ sheet take to print? Inkjets are faster than 
you say and in both cases the computer often has trouble keeping up with the 
printer. 

A sage said to me: "Do you want one copy or lots of copies?", "One", 
"Inkjet".
 
> Something else to think about is the cost of consumables over the
> life of the printer.  A 3000 page yield toner cartridge is about
> $US 75-80 at discount while HP high capacity 
> cartridges are about $US 22 at discount.  It could be that over the
> life cycle of the printer that consumables for laser printers are
> less than ink jet printers.  It is getting progressively closer
> between the two technologies.  Laser printers are usually desinged
> for higher duty cycles in pages per month and longer product
> replacement cycles.

Paper cost is the same and both can use refills. Long term the laserprinter 
will need some expensive replacement parts  and on top of that 
are the amortisation costs which favour the lowest purchase cost printer.

HP inkjets understand PCL so in many cases a laserjet driver will work if the 
software package has no inkjet driver. 

There is one wild difference between the two printers: a laserprinter is a 
page printer whilst an inkjet is a line printer. This means that a 
laserprinter can rotate graphic images whilst an inkjet cannot. Few drivers 
actually use this facility.


  TC. 
    E-mail:  or
sci_med_outliers = df_outliers[df_outliers['Class Name'] == 'sci.med']
print(sci_med_outliers['Text'].iloc[0])
Re: THE BACK MACHINE - Update
Organization: University of Nebraska--Lincoln 
Lines: 15
Distribution: na
NNTP-Posting-Host: unlinfo.unl.edu

   I have a BACK MACHINE and have had one since January.  While I have not 
found it to be a panacea for my back pain, I think it has helped somewhat. 
It MAINLY acts to stretch muscles in the back and prevent spasms associated
with pain.  I am taking less pain medication than I was previously.  
   The folks at BACK TECHNOLOGIES are VERY reluctant to honor their return 
policy.  They extended my "warranty" period rather than allow me to return 
the machine when, after the first month or so, I was not thrilled with it. 
They encouraged me to continue to use it, abeit less vigourously. 
   Like I said, I can't say it is a cure-all, but it keeps me stretched out
and I am in less pain.
--
***********************************************************************
Dale M. Webb, DVM, PhD           *  97% of the body is water.  The
Veterinary Diagnostic Center     *  other 3% keeps you from drowning.
University of Nebraska, Lincoln  *
sci_space_outliers = df_outliers[df_outliers['Class Name'] == 'sci.space']
print(sci_space_outliers['Text'].iloc[0])
MACH 25 landing site bases?
Article-I.D.: aurora.1993Apr5.193829.1
Organization: University of Alaska Fairbanks
Lines: 7
Nntp-Posting-Host: acad3.alaska.edu

The supersonic booms hear a few months ago over I belive San Fran, heading east
of what I heard, some new super speed Mach 25 aircraft?? What military based
int he direction of flight are there that could handle a Mach 25aircraft on its
landing decent?? Odd question??

==
Michael Adams,  -- I'm not high, just jacked

পরবর্তী পদক্ষেপ

আপনি এখন এম্বেডিং ব্যবহার করে একটি অসঙ্গতি সনাক্তকারী তৈরি করেছেন! এম্বেডিং হিসাবে কল্পনা করার জন্য আপনার নিজস্ব পাঠ্য ডেটা ব্যবহার করার চেষ্টা করুন এবং কিছু আবদ্ধ নির্বাচন করুন যাতে আপনি আউটলায়ার সনাক্ত করতে পারেন। ভিজ্যুয়ালাইজেশন ধাপ সম্পূর্ণ করার জন্য আপনি মাত্রিকতা হ্রাস করতে পারেন। নোট করুন যে t-SNE ক্লাস্টারিং ইনপুটগুলিতে ভাল, তবে একত্রিত হতে বেশি সময় নিতে পারে বা স্থানীয় মিনিমাতে আটকে যেতে পারে। আপনি যদি এই সমস্যায় পড়েন, তাহলে আরেকটি কৌশল যা আপনি বিবেচনা করতে পারেন তা হল প্রধান উপাদান বিশ্লেষণ (PCA)

Gemini API-এ অন্যান্য পরিষেবাগুলি কীভাবে ব্যবহার করবেন তা জানতে, Python quickstart-এ যান।

আপনি কীভাবে এমবেডিং ব্যবহার করতে পারেন সে সম্পর্কে আরও জানতে, উপলব্ধ উদাহরণগুলি দেখুন। স্ক্র্যাচ থেকে কীভাবে সেগুলি তৈরি করবেন তা শিখতে, টেনসরফ্লো-এর ওয়ার্ড এমবেডিংস টিউটোরিয়াল দেখুন।