title: Fastai text classifier: batch prediction on unseen data
body: <p>I have being working with fastai's text classifier (<a href="https://docs.fast.ai/text.html" rel="nofollow noreferrer">https://docs.fast.ai/text.html</a>). I currently predict the sentiment (positive or negative) of unseen phrases as it follows:</p>
  
  <pre><code>def _unpack_prediction(self, text) -&gt; Tuple[bool, float]:
      out = self._model.predict(text)
      return str(out[0]) == "positive", max(out[2][0].item(), out[2][1].item())
  
  def example(self, messages: Sequence[str]):
      results = map(self._unpack_prediction, messages)
      for phrase, out in zip(messages, results):
          print(f"{phrase[:100]}...[{'pos' if out[0] else 'neg'}] - [{out[1]:.2f}]")
  </code></pre>
  
  <p>Given a list of phrases:</p>
  
  <pre><code>("I love this movie",
    "The actors are good, but this movie is definitely stupid",
    "There is no plot at all!!! Just special effects ")
  </code></pre>
  
  <p>The result is:</p>
  
  <pre><code>I love this movie...[pos] - [1.00]
  The actors are good, but this movie is definitely stupid...[neg] - [0.96]
  There is no plot at all!!! Just special effects ...[neg] - [0.95]
  </code></pre>
  
  <p>However, sequentially applying prediction on phrases is pretty slow.</p>
  
  <p>Is there a way to apply batch prediction with fastai library without creating a test dataset?</p>