Presentation is loading. Please wait.

Presentation is loading. Please wait.

Language and Vision: Useful Tools Presenter: Vicente Ordonez.

Similar presentations


Presentation on theme: "Language and Vision: Useful Tools Presenter: Vicente Ordonez."— Presentation transcript:

1 Language and Vision: Useful Tools Presenter: Vicente Ordonez

2 Text Analysis Tokenization, Tagging, Parsing, Word Embeddings

3 Python NLTK “My cat likes eating bananas”

4 Python NLTK: Tokenization import nltk nltk.word_tokenize(“My cat likes eating bananas”) >>['My', 'cat', 'likes', 'eating', 'bananas']

5 Python NLTK: POS Tagging import nltk words = nltk.word_tokenize(“My cat likes eating bananas”) nltk.pos_tag(words) >>[(‘My', ‘PRP$'), ('cat', 'NN'), ('likes', 'VBZ'), ('eating', 'VBG'), ('bananas', 'NNS')] Penn Treebank Postagging

6 Python NLTK: Named Entities import nltk words = nltk.word_tokenize(“My uncle Fred’s cat likes eating bananas”) tags = nltk.pos_tag(words) nlkt.ne_chunk(tag) >>Tree('S', [('My', 'PRP$'), ('uncle', 'NN'), Tree('PERSON', [(Fred', 'NNP')]), ("'s", 'POS'), ('cat', 'NN'), ('likes', 'VBZ'), ('eating', 'VBG'), ('bananas', 'NNS')])

7 Python NLTK: Wordnet from nltk.corpus import wordnet wordnet.synsets('dog') // works even if you use ‘dogs’ instead >> [Synset('dog.n.01'), Synset('frump.n.01'), Synset('dog.n.03'), Synset('cad.n.01'), Synset('frank.n.02'), Synset('pawl.n.01'), Synset('andiron.n.01'), Synset('chase.v.01')] synset = wn.synset('dog.n.01') // You can get definition, lemmas, examples, hypernyms (“parent words”), hyponyms (“children words”), etc

8 Python NLTK: Wordnet Similarity from nltk.corpus import wordnet dog = wn.synset('dog.n.01') cat = wn.synset('cat.n.01') similarity_score = dog.path_similarity(cat) similarity_score = dog.wup_similarity(cat)

9 Python Final Advice Python Spyder NLTK Scipy Numpy Matplotlib VTK etc

10 Stanford Core NLP: Parsing Properties props = new Properties(); props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); String text = “My cat likes eating bananas"; Annotation document = new Annotation(text); pipeline.annotate(document); List sentences = document.get(SentencesAnnotation.class); for(CoreMap sentence: sentences) { Tree tree = sentence.get(TreeAnnotation.class); // Do something here with the tree } DEMO:

11 Stanford Core NLP: Dependencies Properties props = new Properties(); props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); String text = “My cat likes eating bananas"; Annotation document = new Annotation(text); pipeline.annotate(document); List sentences = document.get(SentencesAnnotation.class); for(CoreMap sentence: sentences) { SemanticGraph graph = sentence.get( CollapsedCCProcessedDependenciesAnnotation.class); // Do something here with the graph } DEMO:

12 Stanford Core NLP: Sentiment Properties props = new Properties(); props.setProperty("annotators", "tokenize, ssplit, pos, lemma, ner, parse, sentiment"); StanfordCoreNLP pipeline = new StanfordCoreNLP(props); String text = “My cat likes eating bananas"; Annotation document = new Annotation(text); pipeline.annotate(document); List sentences = document.get(SentencesAnnotation.class); for(CoreMap sentence: sentences) { Tree tree = sentence.get(SentimentCoreAnnotations.AnnotatedTree.class); int sentiment = RNNCoreAnnotations.getPredictedClass(tree); // Do something here with the sentiment tree } DEMO:

13 Python Scikit-learn: Bag of Words from sklearn.feature_extraction.text import CountVectorizer vectorizer = CountVectorizer(analyzer = "word", \ tokenizer = tokenize, \ stop_words = “english", \ max_features = 5000) // Compute vocabulary of top 5000 most frequent words corpus_features = vectorizer.fit_transform(text_corpus) // On test data features = vectorizer.transform(‘My cat likes eating bananas’)

14 Word2Vec My cat likes eating bananas [ … ] [ … ] [ … ] [ … ] [ … ] [ … ] Average https://code.google.com/p/word2vec/

15 Word2Vec https://code.google.com/p/word2vec/ Word Cosine distance los_angeles golden_gate oakland california san_diego pasadena seattle taiko houston chicago_illinois Closest words to “san francisco” You can also try:

16 Text Analysis Summary Basic Text Analysis using NTLK Splitting a sentence into words – tokenization. Extracting nouns, verbs, adjectives, etc – POS-tagging Computing word similarities – Wordnet Sentence Parsing using StanfordNLP Breaking sentences into its subject, predicate, etc. Resolving word dependencies. Sentiment Analysis Word representations Bag of Words - Scikit-learn Neural Networks – Word2vec

17 Image Analysis Image representations, shape, color + shape, recognition

18 VLFeat: HOG Features - Matlab image = imread(‘house.jpg’) hog = vl_hog(image, 8)

19 VLFeat: Dense SIFT - Matlab binSize = 8; magnif = 3; image_smooth = vl_imsmooth(I, sqrt((binSize/magnif)^2 -.25)) ; [frames, descriptors] = vl_dsift(image_smooth, 'size', binSize) ;

20 Convolutional Networks Krizhevsky, Sutskever, Hinton (2012)

21 Caffe import caffe caffe_root = 'CAFFE_INSTALLATION_DIRECTORY' caffe.set_mode_cpu() net = caffe.Classifier( caffe_root + 'models/bvlc_reference_caffenet/deploy.prototxt', caffe_root + 'models/bvlc_reference_caffenet/bvlc_reference_caffenet.caffemodel') net.transformer.set_mean('data', np.load(caffe_root + 'python/caffe/imagenet/ilsvrc_2012_mean.npy').mean(1).mean(1)) net.transformer.set_raw_scale('data', 255) net.transformer.set_channel_swap('data', (2,1,0)) scores = net.predict([caffe.io.load_image(caffe_root + 'examples/images/cat.jpg')])

22 Caffe >> scores [('data', (10, 3, 227, 227)), ('conv1', (10, 96, 55, 55)), ('pool1', (10, 96, 27, 27)), ('norm1', (10, 96, 27, 27)), ('conv2', (10, 256, 27, 27)), ('pool2', (10, 256, 13, 13)), ('norm2', (10, 256, 13, 13)), ('conv3', (10, 384, 13, 13)), ('conv4', (10, 384, 13, 13)), ('conv5', (10, 256, 13, 13)), ('pool5', (10, 256, 6, 6)), ('fc6', (10, 4096, 1, 1)), ('fc7', (10, 4096, 1, 1)), ('fc8', (10, 1000, 1, 1)), ('prob', (10, 1000, 1, 1))]

23 RCNN – Detection – Matlab / C https://github.com/rbgirshick/rcnn

24 DPM – Detection – Matlab - C

25 Image Analysis Summary Overview of the VLFeat Library Basic image operators Distance functions, clustering, etc. Computing Features using Caffe / MatConvNet Obtaining category predictions Obtaining intermediate image representations Object Detection RCNN code – C/C++ - Matlab DPM code – C/C++ - Matlab


Download ppt "Language and Vision: Useful Tools Presenter: Vicente Ordonez."

Similar presentations


Ads by Google