docstr: Since we don't filter prefixes for OOV ahead of time, it's possible
  that some of them will have different lengths. When this is the case,
  we can't do RNN prediction in batch.
  
  This method _tries_ to do prediction in batch, and, when it
  fails, just does prediction sequentially and concatenates all of
  the results.
docstr_tok: ["Since","we","do","n't","filter","prefixes","for","OOV","ahead","of","time",",","it","'s","possible","that","some","of","them","will","have","different","lengths",".","When","this","is","the","case",",","we","ca","n't","do","RNN","prediction","in","batch",".","This","method","_tries_","to","do","prediction","in","batch",",","and",",","when","it","fails",",","just","does","prediction","sequentially","and","concatenates","all","of","the","results","."]
code: def query(self, sentences, swapped_words, batch_size=32):
      """Since we don't filter prefixes for OOV ahead of time, it's possible
      that some of them will have different lengths. When this is the case,
      we can't do RNN prediction in batch.
  
      This method _tries_ to do prediction in batch, and, when it
      fails, just does prediction sequentially and concatenates all of
      the results.
      """
      try:
          return self.try_query(
              sentences, swapped_words, batch_size=batch_size
          )
      except Exception:
          probs = []
          for s, w in zip(sentences, swapped_words):
              try:
                  probs.append(
                      self.try_query([s], [w], batch_size=1)[0]
                  )
              except RuntimeError:
                  print(
                      "WARNING:  got runtime error trying languag emodel on language model w s/w",
                      s,
                      w,
                  )
                  probs.append(float("-inf"))
          return probs
  
file_path: TextAttack/textattack/constraints/grammaticality/language_models/learning_to_write/language_model_helpers.py
imports: import os
  import numpy
  import torch
  from textattack.shared.utils import LazyLoader
  from .rnn_model import RNNModel
label_desc: Use image node_id 2 for calling the QueryHandler obj's underlying member method code with example usage: obj.query(sentences, swapped_words, batch_size) and returns: self, probs