Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow TableReader models without aggregation classifier #1772

Merged
merged 1 commit into from
Nov 18, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions haystack/nodes/reader/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,20 @@ def predict(self, query: str, documents: List[Document], top_k: Optional[int] =
# Forward query and table through model and convert logits to predictions
outputs = self.model(**inputs)
inputs.to("cpu")
predicted_answer_coordinates, predicted_aggregation_indices = self.tokenizer.convert_logits_to_predictions(
if self.model.config.num_aggregation_labels > 0:
aggregation_logits = outputs.logits_aggregation.cpu().detach()
else:
aggregation_logits = None

predicted_output = self.tokenizer.convert_logits_to_predictions(
inputs,
outputs.logits.cpu().detach(),
outputs.logits_aggregation.cpu().detach()
aggregation_logits
)
if len(predicted_output) == 1:
predicted_answer_coordinates = predicted_output[0]
else:
predicted_answer_coordinates, predicted_aggregation_indices = predicted_output

# Get cell values
current_answer_coordinates = predicted_answer_coordinates[0]
Expand All @@ -131,7 +140,10 @@ def predict(self, query: str, documents: List[Document], top_k: Optional[int] =
current_answer_cells.append(table.iat[coordinate])

# Get aggregation operator
current_aggregation_operator = self.model.config.aggregation_labels[predicted_aggregation_indices[0]]
if self.model.config.aggregation_labels is not None:
current_aggregation_operator = self.model.config.aggregation_labels[predicted_aggregation_indices[0]]
else:
current_aggregation_operator = "NONE"

# Calculate answer score
current_score = self._calculate_answer_score(outputs.logits.cpu().detach(), inputs, current_answer_coordinates)
Expand Down