!
pip install cohere s
Import cohere
#create your own API key using cohere website
co = [Link]('xRUtfWFXb4fH4tyfWGVNaCpjZJUGHJT6EoUfWoDM')
response = [Link] (model='command-nightly',
prompt='Who are you?',
max_tokens=300,
temperature=0.75, # ... other parameters )
print('Prediction: {}'.format([Link][0].text))
#embedding
Import cohere
co = [Link]("xRUtfWFXb4fH4tyfWGVNaCpjZJUGHJT6EoUfWoDM")
# Replace with your API key
text = "India is my country. I am an Indian"
response = [Link](texts=[text], model="large")
embedding = [Link][0]
print(embedding)
Program executed in Google Colab
Programm 1
Program 9
Program 7 executed
Program 6 executed
Programm 5 is not executed
Programm 4 is not executed
Vision description:
#vision description
Import cohere
co = [Link]("xRUtfWFXb4fH4tyfWGVNaCpjZJUGHJT6EoUfWoDM")
# Replace with your API key
def describe_image(image_url):
response = [Link]( model='command-nightly',
prompt=f'Describe this image: {image_url}',
max_tokens=50, temperature=0.5, )
return [Link][0].text image_url =
"[Link]
[Link]/2560px-Gfp-wisconsin-madison-the
description = describe_image(image_url) print(description)
1st Day
Hugging Face
[Link]
[Link]
[Link]
2nd Day
[Link]
[Link]
[Link]
link for manual
[Link]
Raghu Prasad Konandur
1:58 PM
[Link]
Topic5.1_OpenSource_LLMs
DEEPSEEK
1. Explore pre-
trained word vectors.
Explore word
relationships using
vector arithmetic.
Perform arithmetic
operations and
analyze results.
1. Explore pre-
trained word vectors.
Explore word
relationships using
vector arithmetic.
Perform arithmetic
operations and
analyze results.
1. Explore pre-
trained word vectors.
Explore word
relationships using
vector arithmetic.
Perform arithmetic
operations and
analyze results.
1. Explore pre-trained word vectors. Explore word relationships using vector arithmetic.
Perform arithmetic operations and analyze results.
Import [Link] as api
print("Loading pre-trained word vectors...")
word_vectors = [Link]("glove-wiki-gigaword-100")
def find_similar_words(word, top_n=5):
if word in word_vectors:
return word_vectors.most_similar(word, topn=top_n)
else: return f"Word '{word}' not in vocabulary."
def vector_arithmetic(word1, word2, word3, top_n=5):
try:
results = word_vectors.most_similar (positive=[word1, word2], negative=[word3],
topn=top_n)
return results except KeyError as e:
return str(e)
# Test functions
print("\nTop Similar words to 'king'")
print(find_similar_words("king"))
print("\nVector arithmetic: king - man + woman = ?")
print(vector_arithmetic("king","woman","man"))
OR
The below programm can run in Python
import [Link] as api
# Load pre-trained word vectors (e.g., Word2Vec or GloVe)
word_vectors = [Link]("word2vec-google-news-300")
# Or "glove-wiki-gigaword-50"
# Example: Find similar words to "king"
similar_words = word_vectors.most_similar("king", topn=5)
print(f"Similar words to 'king': {similar_words}")
# Example: Explore the "king - man + woman" analogy
king_vector = word_vectors["king"]
man_vector = word_vectors["man"]
woman_vector = word_vectors["woman"]
# Calculate the vector for "queen"
queen_vector = king_vector - man_vector + woman_vector
# Find the word closest to the calculated vector
closest_word = word_vectors.similar_by_vector(queen_vector, topn=1)
print(f"The word closest to the calculated vector is: {closest_word}")
Use dimensionality
reduction (e.g., PCA
or t-SNE) to visualize
word
embeddings for Q 1.
Select 10 words from
a specific domain
(e.g.,
sports, technology)
and visualize their
embeddings.
Analyze clusters and
2. Use dimensionality reduction (e.g., PCA or t-SNE) to visualize word embeddings for Q 1.
Select 10 words from a specific domain (e.g., sports, technology) and visualize their
embeddings. Analyze clusters and relationships. Generate contextually rich outputs using
embeddings. Write a program to generate 5 semantically similar words for a given input.
# Import
necessary libraries
import gensim
from [Link]
import Word2Vec
import numpy as np
import
[Link] as
plt
from
[Link]
n import PCA
#import gensim
from [Link] import Word2Vec
import re
import pandas as pd
import [Link] as plt
from [Link] import PCA
# Sample domain-specific corpus (Technology)
technology_corpus = [
"Artificial intelligence is transforming various industries.",
"Machine learning algorithms improve predictive analytics.",
"Cloud computing enables scalable infrastructure for businesses.",
"Cybersecurity is crucial for protecting sensitive data.",
"Blockchain technology ensures secure and decentralized transactions.",
"The Internet of Things connects smart devices seamlessly.",
"Big data analytics helps organizations make data-driven decisions.",
"Quantum computing has the potential to revolutionize cryptography.",
"Edge computing brings computation closer to data sources.",
"Natural language processing enhances human-computer interactions."
]
# Basic text preprocessing function (tokenization & lowercasing)
def simple_tokenize(text):
return [Link](r'\b\w+\b', [Link]())
# Preprocess corpus manually
preprocessed_corpus = [simple_tokenize(sentence) for sentence in
technology_corpus]
# Train Word2Vec model
model = Word2Vec(sentences=preprocessed_corpus, vector_size=50, window=5,
min_count=1, workers=4)
# Select 10 domain-specific words
selected_words = ["ai", "machine", "cloud", "cybersecurity", "blockchain",
"iot", "data", "quantum", "edge", "nlp"]
# Filter selected words to include only words present in [Link]
selected_words = [word for word in selected_words if word in [Link]]
# Extract word embeddings for selected words
word_vectors = [[Link][word] for word in selected_words if word in
[Link]]
# Reduce dimensionality using PCA
pca = PCA(n_components=2)
reduced_vectors = pca.fit_transform(word_vectors)
# Create DataFrame for visualization
df_embeddings = [Link](reduced_vectors, columns=["x", "y"],
index=selected_words)
# Plot embeddings
[Link](figsize=(10, 6))
[Link](df_embeddings["x"], df_embeddings["y"], marker='o')
for word, (x, y) in zip(df_embeddings.index, reduced_vectors):
[Link](x, y, word, fontsize=12)
[Link]("PCA Component 1")
[Link]("PCA Component 2")
[Link]("Word Embeddings Visualization (Technology Domain)")
[Link]()
# Function to get semantically similar words
def get_similar_words(word, top_n=5):
if word in [Link]:
return [Link].most_similar(word, topn=top_n)
else:
return f"Word '{word}' not in vocabulary."
# Example usage
input_word = "technology"
similar_words = get_similar_words(input_word)
print(f"Top 5 words similar to '{input_word}':", similar_words)