Adrien commited on
Commit ·
bccb279
1
Parent(s): 3823e3e
clean up
Browse files10 unmodified lines1112131415165 unmodified lines222324252627289 unmodified lines38394041424310 unmodified linesclass SourceAnnotator:def __init__(self):self.source_annotator = pipeline("question-answering",model="distilbert/distilbert-base-cased-distilled-squad",5 unmodified linesfor sentence in sentences:scores = []for chunk in reranked_chunks:score = self.annotate_source(sentence.lower(), chunk.content.lower())score["filename"] = chunk.metadata["filename"].split(".pdf")[0]score["chunk_id"] = chunk.chunk_idscores.append(score)9 unmodified linespattern = r"(?<=[.!?])\s+(?=[A-Z])"sentences = re.split(pattern, text)return [s.strip() for s in sentences if s.strip()]def annotate_source(self, text: str, chunk: str) -> dict:return self.source_annotator(text, chunk)10 unmodified lines111213141516175 unmodified lines232425262728299 unmodified lines39404110 unmodified linesclass SourceAnnotator:def __init__(self):# Extractive question answering modelself.source_annotator = pipeline("question-answering",model="distilbert/distilbert-base-cased-distilled-squad",5 unmodified linesfor sentence in sentences:scores = []for chunk in reranked_chunks:score = self.source_annotator(sentence.lower(), chunk.content.lower())score["filename"] = chunk.metadata["filename"].split(".pdf")[0]score["chunk_id"] = chunk.chunk_idscores.append(score)9 unmodified linespattern = r"(?<=[.!?])\s+(?=[A-Z])"sentences = re.split(pattern, text)return [s.strip() for s in sentences if s.strip()]
rag_demo/rag/source_annotator.py+2-4