title: HuggingFace Bert Sentiment analysis
body: <p>I am getting the following error :</p>
  <p><code>AssertionError: text input must of type str (single example), List[str] (batch or single pretokenized example) or List[List[str]] (batch of pretokenized examples).</code>, when I run <code>classifier(encoded)</code>. My text type is <code>str</code> so I am not sure what I am doing wrong. Any help is very appreciated.</p>
  <pre class="lang-py prettyprint-override"><code>import torch
  from transformers import AutoTokenizer, BertTokenizer, BertModel, BertForMaskedLM, AutoModelForSequenceClassification, pipeline
  
  # OPTIONAL: if you want to have more information on what's happening under the hood, activate the logger as follows
  import logging
  logging.basicConfig(level=logging.INFO)
  
  # Load pre-trained model tokenizer (vocabulary)
  # used the cased instead of uncased to account for cases like BAD.
  tokenizer = BertTokenizer.from_pretrained('bert-base-cased') 
  
  
  # alternative? what is the difference between these two tokenizers? 
  #tokenizer = AutoTokenizer.from_pretrained(&quot;textattack/bert-base-uncased-SST-2&quot;)
  
  model = AutoModelForSequenceClassification.from_pretrained(&quot;textattack/bert-base-uncased-SST-2&quot;)
  
  
  # feed the model and the tokenizer into the pipeline
  classifier = pipeline('sentiment-analysis', model=model, tokenizer= tokenizer)
  
  
  #---------------sample raw input passage--------
  
  text = &quot;Who was Jim Henson ? Jim Henson was a puppeteer. He is simply awful.&quot;
  # tokenized_text = tokenizer.tokenize(text)
  
  #----------Tokenization and Padding---------
  # Encode the sentences to get tokenized and add padding stuff
  encoded = tokenizer.encode_plus(
      text=text,  # the sentences to be encoded
      add_special_tokens=True,  # Add [CLS] and [SEP] !!!
      max_length = 64,  # maximum length of a sentence  (TODO Figure the longest passage length)
      pad_to_max_length=True,  # Add [PAD]s
      return_attention_mask = True,  # Generate the attention mask
      truncation=True,  #explicitly truncate examples to max length
      return_tensors = 'pt',  # ask the function to return PyTorch tensors
  )
  
  #-------------------------------------------
  # view the IDs
  for key, value in encoded.items():
      print(f&quot;{key}: {value.numpy().tolist()}&quot;)
      
  #-------------------------------------------
  
  
  classifier(encoded)
  
  </code></pre>