logitorch.models.ruletaker¶
Classes¶
RuleTaker is a PyTorch module for rule-based question answering using the Roberta model. |
Module Contents¶
- class logitorch.models.ruletaker.RuleTaker(num_labels: int = 2)[source]¶
Bases:
torch.nn.ModuleRuleTaker is a PyTorch module for rule-based question answering using the Roberta model.
- Args:
num_labels (int): The number of labels for classification. Default is 2.
- Attributes:
num_labels (int): The number of labels for classification. encoder (RobertaForMultipleChoice): The Roberta model for multiple choice tasks. config (RobertaConfig): The configuration of the Roberta model. classifier (RobertaClassificationHead): The classification head of the Roberta model. tokenizer (RobertaTokenizer): The tokenizer for the Roberta model.
- Methods:
forward(x, y=None): Performs forward pass of the RuleTaker model. predict(context, question, device=”cpu”): Predicts the answer label for a given context and question.
Initializes a RuleTaker instance.
- Args:
num_labels (int): The number of labels for classification. Default is 2.
- forward(x, y=None)[source]¶
Performs forward pass of the RuleTaker model.
- Args:
x (dict): The input dictionary containing the context and question. y (Tensor): The target labels. Default is None.
- Returns:
outputs (tuple): A tuple containing the logits and other outputs.
- predict(context: str, question: str, device: str = 'cpu') int[source]¶
Predicts the answer label for a given context and question.
- Args:
context (str): The context for the question. question (str): The question to be answered. device (str): The device to run the prediction on. Default is “cpu”.
- Returns:
pred (int): The predicted answer label.