-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from ittia-research/dev
change to multi-sources mode
- Loading branch information
Showing
20 changed files
with
701 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
FROM pytorch/pytorch:2.4.0-cuda12.4-cudnn9-runtime | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.*.txt /app | ||
RUN pip install --no-cache-dir -r requirements.base.txt | ||
RUN pip install --no-cache-dir -r requirements.local.txt | ||
COPY . /app | ||
EXPOSE 8000 | ||
|
||
WORKDIR /app/src | ||
|
||
COPY ./src . | ||
|
||
EXPOSE 8000 | ||
|
||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
FROM python:3.11-slim-bookworm | ||
|
||
WORKDIR /app | ||
|
||
COPY requirements.base.txt /app | ||
RUN pip install --no-cache-dir -r requirements.base.txt | ||
COPY . /app | ||
EXPOSE 8000 | ||
|
||
WORKDIR /app/src | ||
|
||
COPY ./src . | ||
|
||
EXPOSE 8000 | ||
|
||
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import dspy | ||
import re | ||
from dsp.utils import deduplicate | ||
|
||
class CheckStatement(dspy.Signature): | ||
"""Verify the statement based on the provided context.""" | ||
context = dspy.InputField(desc="Facts here are assumed to be true.") | ||
statement = dspy.InputField() | ||
verdict = dspy.OutputField(desc=("In order," | ||
" `False` if the context directly negates the statement," | ||
" `True` if it directly supports the statement," | ||
" else `Irrelevant`.")) | ||
|
||
""" | ||
LM sometimes reply additional words after the verdict, this function address the issue. | ||
""" | ||
def extract_verdict(input): | ||
# Extract the first word | ||
match = re.match(r'\s*(\w+)', input) | ||
if match: | ||
first_word = match.group(1) | ||
if first_word.lower() in ['false', 'true', 'irrelevant']: | ||
# Return verdict with the first letter capitalized | ||
return first_word.capitalize() | ||
# If no in the verdict list, return the input directly | ||
return input | ||
|
||
class GenerateSearchQuery(dspy.Signature): | ||
"""Write a search query that will help retrieve additional info related to the statement.""" | ||
context = dspy.InputField(desc="Existing context.") | ||
statement = dspy.InputField() | ||
query = dspy.OutputField() | ||
|
||
""" | ||
SimplifiedBaleen module | ||
Avoid unnecessary content in module cause MIPROv2 optimizer will analize modules. | ||
To-do: | ||
- retrieve latest facts | ||
- query results might stays the same in hops: better retrieval | ||
""" | ||
class ContextVerdict(dspy.Module): | ||
def __init__(self, passages_per_hop=3, max_hops=3): | ||
super().__init__() | ||
# self.generate_query = dspy.ChainOfThought(GenerateSearchQuery) # IMPORTANT: solves error `list index out of range` | ||
self.generate_query = [dspy.ChainOfThought(GenerateSearchQuery) for _ in range(max_hops)] | ||
self.retrieve = dspy.Retrieve(k=passages_per_hop) | ||
self.generate_verdict = dspy.ChainOfThought(CheckStatement) | ||
self.max_hops = max_hops | ||
|
||
def forward(self, statement): | ||
context = [] | ||
for hop in range(self.max_hops): | ||
query = self.generate_query[hop](context=context, statement=statement).query | ||
passages = self.retrieve(query).passages | ||
context = deduplicate(context + passages) | ||
|
||
_verdict_predict = self.generate_verdict(context=context, statement=statement) | ||
verdict = extract_verdict(_verdict_predict.verdict) | ||
pred = dspy.Prediction(answer=verdict, rationale=_verdict_predict.rationale, context=context) | ||
return pred |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
## Optimizer Card | ||
verdict_MIPROv2: | ||
- datasets: | ||
- size: train 1002, val 500, test 498 | ||
- source: generated from HotPotQA | ||
- quality: low | ||
- optimizer: MIPROv2 | ||
- compile: | ||
- model: mistralai/Mistral-Nemo-Instruct-2407 | ||
- init_temperature: 1 | ||
- num_candidates: 20 | ||
- num_batches: 120 | ||
- max_bootstrapped_demos: 4 | ||
- max_labeled_demos: 4 | ||
- version: | ||
- dspy-ai==2.4.13 |
Oops, something went wrong.