Jaccard-Text-Similarity-1
title: "Jaccard Text Similarity 1"
author: "Rj"
date: 2019-04-21
description: "-"
type: technical_note
draft: false
def get_jaccard_similarity(content1, content2):
content1_similarity = set(content1.split())
content2_similarity = set(content2.split())
intersection = content1_similarity.intersection(content2_similarity)
return float(len(intersection)) / (len(content1_similarity) + len(content2_similarity) - len(intersection))
# test 2
content1 = "These data could show that the people …
Read More
Json Output Parser
from constants import OPENAI_API_KEY
!pip show langchain-openai | grep "Version:"
os.environ["OPENAI_API_KEY"] = OPENAI_API_KEY
from langchain_openai import ChatOpenAI
model = ChatOpenAI(model="gpt-4o-mini")
from langchain_core.output_parsers import JsonOutputParser
chain = (
model | JsonOutputParser()
) # Due to a bug in older versions of Langchain, JsonOutputParser did not stream results …
Read More
Json-To-Xml
title: "JSON to XML"
author: "Rj"
date: 2019-04-20
description: "List Test"
type: technical_note
draft: false
content = {
"note" : {
"to" : "Tove",
"from" : "Jani",
"heading" : "Reminder",
"body" : "Don't forget me this weekend!"
}
}
{'note': {'body': "Don't forget me this weekend!",
'from': 'Jani',
'heading': 'Reminder',
'to': 'Tove'}}
xml = xmltodict.unparse …
Read More
Lambda-Custom
title: "Lambda Custom"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
cities = [
'chennai', 'delhi', 'madurai', 'pune', 'bengaluru'
]
['chennai', 'delhi', 'madurai', 'pune', 'bengaluru']
def is_south_indian_city(city):
if city == 'chennai' or city == 'madurai' or city == 'bengaluru':
return True
return False
new_list = list(filter(lambda x: is_south_indian_city(x) , cities …
Read More
Lambda-Odd
title: "Lambda Odd"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
def is_odd(digit):
if digit % 2 != 0:
return True
return False
digits = [
1, 7, 18, 2, 4, 2, 8, 5, 3
]
[1, 7, 18, 2, 4, 2, 8, 5, 3]
new_list = list(filter(lambda x …
Read More
Lambda-Sqaure
title: "Lambda Square"
author: "Raja CSP Raman"
date: 2019-04-20
description: "-"
type: technical_note
draft: false
squares = list(map(lambda x: x**2, range(10)))
[0, 1, 4, 9, 16, 25, 36, 49, 64, 81]
Score: 0
Read More
Lancaster-Stemmer
title: "Lancaster Stemmer"
author: "Rj"
date: 2019-04-21
description: "-"
type: technical_note
draft: false
from nltk.stem import LancasterStemmer
l_stemmer = LancasterStemmer()
print(l_stemmer.stem("hunting"))
print(l_stemmer.stem("hunting"))
words = [
"hunting",
"bunnies",
"flies"
]
result = [l_stemmer.stem(word) for word in words]
Score: 5
Read More