Description

Hash every word as a number, and save the inverse document frequency(IDF) of every word in the document.

It’s used together with DocHashCountVectorizerPredictBatchOp.

Parameters

Name Description Type Required? Default Value
selectedCol Name of the selected column used for processing String
numFeatures The number of features. It will be the length of the output vector. Integer 262144
minDF When the number of documents a word appears in is below minDF, the word will not be included in the dictionary. It could be an exact countor a fraction of the document number count. When minDF is within [0, 1), it’s used as a fraction. Double 1.0
featureType Feature type, support IDF/WORD_COUNT/TF_IDF/Binary/TF String “WORD_COUNT”
minTF When the number word in this document in is below minTF, the word will be ignored. It could be an exact count or a fraction of the document token count. When minTF is within [0, 1), it’s used as a fraction. Double 1.0

Script Example

Code

  1. import numpy as np
  2. import pandas as pd
  3. data = np.array([
  4. [0, u'二手旧书:医学电磁成像'],
  5. [1, u'二手美国文学选读( 下册 )李宜燮南开大学出版社 9787310003969'],
  6. [2, u'二手正版图解象棋入门/谢恩思主编/华龄出版社'],
  7. [3, u'二手中国糖尿病文献索引'],
  8. [4, u'二手郁达夫文集( 国内版 )全十二册馆藏书']])
  9. df = pd.DataFrame({"id": data[:, 0], "text": data[:, 1]})
  10. inOp1 = BatchOperator.fromDataframe(df, schemaStr='id int, text string')
  11. inOp2 = StreamOperator.fromDataframe(df, schemaStr='id int, text string')
  12. segment = SegmentBatchOp().setSelectedCol("text").linkFrom(inOp1)
  13. train = DocHashCountVectorizerTrainBatchOp().setSelectedCol("text").linkFrom(segment)
  14. predictBatch = DocHashCountVectorizerPredictBatchOp().setSelectedCol("text").linkFrom(train, segment)
  15. [model,predict] = collectToDataframes(train, predictBatch)
  16. print(model)
  17. print(predict)
  18. segment = SegmentStreamOp().setSelectedCol("text").linkFrom(inOp2)
  19. predictStream = DocHashCountVectorizerPredictStreamOp(train).setSelectedCol("text").linkFrom(segment)
  20. predictStream.print(refreshInterval=-1)
  21. StreamOperator.execute()

Results

Model
  1. rowID model_id model_info
  2. 0 0 {"numFeatures":"262144","minTF":"1.0","feature...
  3. 1 1048576 {"0":-0.6061358035703156,"37505":1.09861228866...
Output Data
  1. id text
  2. 0 0 $262144$10121:1.0 64444:1.0 119456:1.0 206232:...
  3. 1 1 $262144$0:6.0 37505:1.0 46743:1.0 93228:1.0 11...
  4. 2 2 $262144$40170:1.0 70777:1.0 96509:1.0 126159:1...
  5. 3 3 $262144$206232:1.0 214785:1.0 251090:1.0 25565...
  6. 4 4 $262144$0:4.0 87711:1.0 138080:1.0 162140:1.0 ...