out[ ]beautiful blue brown dog fox jumps lazy love quick sky today thusthe preceding output depicts the tf-idf based feature vectors for each of our text documents notice how this is scaled and normalized version as compared to the raw bag of words model interested readers who might want to dive into further details of how the internals of this model work can refer to page of text analytics with python (apressdipanjan sarkar document similarity you can even build on top of the tf-idf based features we engineered in the previous section and use them to generate new features which can be useful in multiple applications an example of this is computing document similarity this is very useful in domains like search enginesdocument clusteringand information retrieval document similarity is the process of using distance or similarity based metric that can be used to identify how similar text document is with another document based on features extracted from the documents like bag of words or tf-idf pairwise document similarity in corpus involves computing document similarity for each pair of documents in corpus thus if you have documents in corpusyou would end up with matrix such that each row and column represents the similarity score for pair of documentswhich represent the indices at the row and columnrespectively there are several similarity and distance metrics that are used to compute document similarity these include cosine distance/similaritybm distancehellinger-bhattacharya distancejaccard distanceand so on in our analysiswe will be using perhaps the most popular and widely used similarity metriccosine similarity cosine similarity basically gives us metric representing the cosine of the angle between the feature vector representations of two text documents figure - shows some typical feature vector alignments for text documents figure - cosine similarity depictions for text document feature vectors (sourcetext analytics with pythonapress