title: How can I use sklearn CountVectorizer with mutliple strings?
body: <p>I have a list of strings (10,000s). Some of the strings constitute multiple words. I have another list which contains some sentences. I am trying to do a count of the number of times each string in my list appears in each sentence. </p>
  
  <p>At present I am using sklearn's feature extraction tool, because it works very quickly when we have 10,000s of strings to look up and 10,000s of sentences.</p>
  
  <p>Below is a simplified version of my code. </p>
  
  <pre><code>import numpy as np
  from sklearn import feature_extraction
  
  sentences = ["hi brown cow", "red ants", "fierce fish"]
  
  listOfStrings = ["brown cow", "ants", "fish"]
  
  cv = feature_extraction.text.CountVectorizer(vocabulary=listOfStrings)
  taggedSentences = cv.fit_transform(sentences).toarray()
  
  taggedSentencesCutDown = taggedSentences &gt; 0
  # Here we get an array of tuples &lt;sentenceIndex, stringIndexfromStringList&gt;
  taggedSentencesCutDown = np.column_stack(np.where(taggedSentencesCutDown))
  </code></pre>
  
  <p>at the moment, if you run this the output is the following:</p>
  
  <pre><code>In [2]: taggedSentencesCutDown
  Out[2]: array([[1, 1], [2, 2]])
  </code></pre>
  
  <p>what I want is:</p>
  
  <pre><code>In [2]: taggedSentencesCutDown
  Out[2]: array([[0,0], [1, 1], [2, 2]])
  </code></pre>
  
  <p>My current use of CountVectorizer shows that it is not looking for multiple word strings. Is there someway else to do this without going into long for loops. Efficiency and time are quite important for my app as my lists are in the 10,000s.</p>
  
  <p>Thanks</p>