Intro
InĀ [1]:
Copied!
# To install
# !pip install intellikit
#To load and use the package
import intellikit as ik
# To install
# !pip install intellikit
#To load and use the package
import intellikit as ik
/home/runner/.local/lib/python3.11/site-packages/sentence_transformers/cross_encoder/CrossEncoder.py:13: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html from tqdm.autonotebook import tqdm, trange
InĀ [2]:
Copied!
import pandas as pd
# Define the questions and answers
questions = [
"What are the admission requirements for universities in Uganda?",
"How can I apply for a scholarship?",
"What is the curriculum for primary schools in Uganda?",
"Where can I find information about school fees?",
"What are the contact details for the Ministry of Education?"
]
answers = [
"The admission requirements for universities in Uganda vary depending on the institution. It is recommended to visit the website of the specific university you are interested in for detailed information.",
"Scholarship applications are usually managed by different organizations and institutions. You can check the Ministry of Education's website for information on available scholarships and application procedures.",
"The curriculum for primary schools in Uganda is designed by the National Curriculum Development Centre (NCDC). You can visit their website for detailed information on the curriculum.",
"Information about school fees can be obtained from the respective schools or educational institutions. It is recommended to contact the schools directly for accurate and up-to-date fee information.",
"You can find the contact details for the Ministry of Education on their official website. They usually provide phone numbers, email addresses, and physical addresses for different departments and offices."
]
# Create the dataframe
df = pd.DataFrame({'Question': questions, 'Answer': answers})
# Print the dataframe
print(df)
import pandas as pd
# Define the questions and answers
questions = [
"What are the admission requirements for universities in Uganda?",
"How can I apply for a scholarship?",
"What is the curriculum for primary schools in Uganda?",
"Where can I find information about school fees?",
"What are the contact details for the Ministry of Education?"
]
answers = [
"The admission requirements for universities in Uganda vary depending on the institution. It is recommended to visit the website of the specific university you are interested in for detailed information.",
"Scholarship applications are usually managed by different organizations and institutions. You can check the Ministry of Education's website for information on available scholarships and application procedures.",
"The curriculum for primary schools in Uganda is designed by the National Curriculum Development Centre (NCDC). You can visit their website for detailed information on the curriculum.",
"Information about school fees can be obtained from the respective schools or educational institutions. It is recommended to contact the schools directly for accurate and up-to-date fee information.",
"You can find the contact details for the Ministry of Education on their official website. They usually provide phone numbers, email addresses, and physical addresses for different departments and offices."
]
# Create the dataframe
df = pd.DataFrame({'Question': questions, 'Answer': answers})
# Print the dataframe
print(df)
Question \ 0 What are the admission requirements for univer... 1 How can I apply for a scholarship? 2 What is the curriculum for primary schools in ... 3 Where can I find information about school fees? 4 What are the contact details for the Ministry ... Answer 0 The admission requirements for universities in... 1 Scholarship applications are usually managed b... 2 The curriculum for primary schools in Uganda i... 3 Information about school fees can be obtained ... 4 You can find the contact details for the Minis...
InĀ [3]:
Copied!
#Define you similarity calculation methods for your project
cosine = ik.sim_sentence_cosine
# Assign the similarity calculation function to the feature
similarity_functions = {
'Question': cosine
}
# Weighting out feature. Since this is just one feature the default weight of one should be used.
feature_weights = {
'Question': 1
}
#How many results do we need. Just one is enough since this is a QA system. You could also opt for multiple results to give users multiple options
top_n = 1
#Define you similarity calculation methods for your project
cosine = ik.sim_sentence_cosine
# Assign the similarity calculation function to the feature
similarity_functions = {
'Question': cosine
}
# Weighting out feature. Since this is just one feature the default weight of one should be used.
feature_weights = {
'Question': 1
}
#How many results do we need. Just one is enough since this is a QA system. You could also opt for multiple results to give users multiple options
top_n = 1
InĀ [4]:
Copied!
#Define your query
query = pd.DataFrame({
'Question': ['Where can i apply for a scholarship?']
})
returned_df = ik.linearRetriever(df, query, similarity_functions, feature_weights, top_n)
returned_dict = ik.dataframe_to_dict(df=returned_df, orientation="records")
returned_dict
#Define your query
query = pd.DataFrame({
'Question': ['Where can i apply for a scholarship?']
})
returned_df = ik.linearRetriever(df, query, similarity_functions, feature_weights, top_n)
returned_dict = ik.dataframe_to_dict(df=returned_df, orientation="records")
returned_dict
Out[4]:
[{'Question': 'How can I apply for a scholarship?', 'Answer': "Scholarship applications are usually managed by different organizations and institutions. You can check the Ministry of Education's website for information on available scholarships and application procedures."}]
InĀ [5]:
Copied!
response = returned_dict[0]['Answer']
ik.stream_text(response)
response = returned_dict[0]['Answer']
ik.stream_text(response)
S
c
h
o
l
a
r
s
h
i
p
a
p
p
l
i
c
a
t
i
o
n
s
a
r
e
u
s
u
a
l
l
y
m
a
n
a
g
e
d
b
y
d
i
f
f
e
r
e
n
t
o
r
g
a
n
i
z
a
t
i
o
n
s
a
n
d
i
n
s
t
i
t
u
t
i
o
n
s
.
Y
o
u
c
a
n
c
h
e
c
k
t
h
e
M
i
n
i
s
t
r
y
o
f
E
d
u
c
a
t
i
o
n
'
s
w
e
b
s
i
t
e
f
o
r
i
n
f
o
r
m
a
t
i
o
n
o
n
a
v
a
i
l
a
b
l
e
s
c
h
o
l
a
r
s
h
i
p
s
a
n
d
a
p
p
l
i
c
a
t
i
o
n
p
r
o
c
e
d
u
r
e
s
.
InĀ [6]:
Copied!
query = pd.DataFrame({
'Question': ['How do i contact the ministry of education?']
})
returned_df = ik.linearRetriever(df, query, similarity_functions, feature_weights, top_n)
returned_dict = ik.dataframe_to_dict(df=returned_df, orientation="records")
response = returned_dict[0]['Answer']
ik.stream_text(response) #returns the response in an animated manner like chatgpt
query = pd.DataFrame({
'Question': ['How do i contact the ministry of education?']
})
returned_df = ik.linearRetriever(df, query, similarity_functions, feature_weights, top_n)
returned_dict = ik.dataframe_to_dict(df=returned_df, orientation="records")
response = returned_dict[0]['Answer']
ik.stream_text(response) #returns the response in an animated manner like chatgpt
Y
o
u
c
a
n
f
i
n
d
t
h
e
c
o
n
t
a
c
t
d
e
t
a
i
l
s
f
o
r
t
h
e
M
i
n
i
s
t
r
y
o
f
E
d
u
c
a
t
i
o
n
o
n
t
h
e
i
r
o
f
f
i
c
i
a
l
w
e
b
s
i
t
e
.
T
h
e
y
u
s
u
a
l
l
y
p
r
o
v
i
d
e
p
h
o
n
e
n
u
m
b
e
r
s
,
e
m
a
i
l
a
d
d
r
e
s
s
e
s
,
a
n
d
p
h
y
s
i
c
a
l
a
d
d
r
e
s
s
e
s
f
o
r
d
i
f
f
e
r
e
n
t
d
e
p
a
r
t
m
e
n
t
s
a
n
d
o
f
f
i
c
e
s
.