Skip to content

Commit

Permalink
Basic QnA using tabular data of VNR #15
Browse files Browse the repository at this point in the history
  • Loading branch information
head-iie-vnr committed Jun 30, 2024
1 parent 8940958 commit ca040f6
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
29 changes: 29 additions & 0 deletions gen-ai/tabular/google-tapas/vnr-data.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
S. No.,JNTUH Faculty Registration Number,Name of the Faculty Member,Designation,Highest Qualification,Department
1,59150406-115722,Challa Dhanunjaya Naidu,Principal & Professor,Ph. D. ECE,Principal
2,66150402-143755,Amjad Shaik,Professor,Ph. D. Automobile,Automobile
3,63150402-144531,Praveen Kumar Thanikonda,Assistant Professor,M. E. Automobile,Automobile
4,90150407-143953,Gumma V L Prasad,Assistant Professor,M.Tech. Automobile,Automobile
5,1180-150410-161243,Kodanda Ram Kuchimanchi,Associate Professor,M. E. Automobile,Automobile
6,2015-150413-105826,Ramu Ratlavath,Assistant Professor,M.Tech. Automobile,Automobile
7,0476-161026-142919,Mohamadaziz Athani,Assistant Professor,M.Tech. Automobile,Automobile
8,7560-170520-172558,Manda Krishna,Assistant Professor,M. E. Automobile,Automobile
9,6710-170522-121340,Jakkula Snothaswini,Assistant Professor,M.Tech. Automobile,Automobile
10,1714-170523-151148,Balappa Hadagali,Assistant Professor,M.Tech. Automobile,Automobile
11,6071-180104-113045,Shet Nagaraj,Assistant Professor,M.Tech. Automobile,Automobile
12,6835-180208-222923,Rathinam Veerappan,Assistant Professor,Ph. D. Automobile,Automobile
13,2324-181123-000547,Gouthami Koduri,Assistant Professor,M. E. Automobile,Automobile
14,1015-191113-144449,Thirunavakarasu Sukumaran Krishnakumar,Assistant Professor,M. E. Automobile,Automobile
15,64150404-125217,Hanumara Rajitha,Assistant Professor,M. Sc. Chemistry,Chemistry
16,90150404-163902,Jyotsna Cherukuri,Associate Professor,Ph. D. Chemistry,Chemistry
17,91150406-113838,Mamatha Nakka,Assistant Professor,Ph. D. Chemistry,Chemistry
18,07150406-161954,Kondapavuluri Madhavi,Assistant Professor,Ph. D. Chemistry,Chemistry
19,46150406-214230,Padmavathi Papolu,Assistant Professor,Ph. D. Chemistry,Chemistry
20,3827-160307-131739,Kum Shuchitiwari,Assistant Professor,Ph. D. Chemistry,Chemistry
21,6687-160316-165018,Regun Balavardhana Rao Adapa,Assistant Professor,Ph. D. Chemistry,Chemistry
22,3492-161216-195533,Pratyusha Satavalli,Assistant Professor,M. Sc. Chemistry,Chemistry
23,1983-161226-003818,Lakshmi Viveka Tella,Assistant Professor,Ph. D. Chemistry,Chemistry
24,5304-150430-153137,Jyothi Sabbani,Assistant Professor,M. Sc. Chemistry,Chemistry
25,6441-161216-172334,Sultana Nazma,Assistant Professor,M. Sc. Chemistry,Chemistry
26,25150406-185744,Padmaja Kakumanu,Assistant Professor,Ph. D. Chemistry,Chemistry
27,0745-150409-122315,Suresh Kommu,Assistant Professor,M. E. Civil Engineering,Civil Engineering
28,7749-151219-181423,Kadali Srinivas,Associate Professor,Ph. D. Civil Engineering,Civil Engineering
44 changes: 44 additions & 0 deletions gen-ai/tabular/google-tapas/vnr-staff-qna-system.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import pandas as pd
from transformers import TapasTokenizer, TapasForQuestionAnswering

# Step 1: Load the model and tokenizer
model_name = "google/tapas-base-finetuned-wtq"
tokenizer = TapasTokenizer.from_pretrained(model_name)
model = TapasForQuestionAnswering.from_pretrained(model_name)

# Step 2: Read the table data from a CSV file and convert all cells to strings
table = pd.read_csv('vnr-data.csv').astype(str)

# Step 3: Define the questions
queries = ["What is Designation of C D Naidu", "Which Department Gouthami Koduri belong to?"]

# Step 4: Tokenize the input
inputs = tokenizer(table=table, queries=queries, padding="max_length", return_tensors="pt")

# Step 5: Get predictions
outputs = model(**inputs)
logits = outputs.logits

# Step 6: Post-process the predictions
predicted_answer_coordinates, predicted_aggregation_indices = tokenizer.convert_logits_to_predictions(
inputs,
outputs.logits.detach(),
outputs.logits_aggregation.detach()
)

# Extract and print the answers
answers = []
for coordinates in predicted_answer_coordinates:
if len(coordinates) == 1:
answer = table.iat[coordinates[0]]
else:
answer = " & ".join(table.iat[coord] for coord in coordinates)
answers.append(answer)

for query, answer in zip(queries, answers):
print(f"Question: {query}")
print(f"Answer: {answer}")

# Optional: Save results to a CSV file
df = pd.DataFrame({"Question": queries, "Answer": answers})
df.to_csv("qa_results.csv", index=False)

0 comments on commit ca040f6

Please sign in to comment.