Skip to content

Commit

Permalink
type hint
Browse files Browse the repository at this point in the history
  • Loading branch information
DianLiI committed Apr 6, 2021
1 parent 5a89282 commit 3eae958
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions forte_wrapper/allennlp/allennlp_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import itertools
import logging
import more_itertools
from typing import Any, Dict, List
from typing import Any, Dict, Iterable, Iterator, List

from allennlp.predictors import Predictor

Expand Down Expand Up @@ -139,11 +139,12 @@ def _process(self, input_pack: DataPack):
self._process_existing_entries(input_pack)

batch_size: int = self.configs['infer_batch_size']
batches: Iterator[Iterable[Sentence]]
if batch_size <= 0:
batches = iter([input_pack.get(Sentence)])
else:
batches = more_itertools.ichunked(input_pack.get(Sentence),
batch_size)
batches = more_itertools.chunked(
input_pack.get(Sentence), batch_size)
for sentences in batches:
inputs: List[Dict[str, str]] = [{"sentence": s.text}
for s in sentences]
Expand Down

0 comments on commit 3eae958

Please sign in to comment.