I wrote on machine learning algorithm that works perfectly now I have to iterate all the items of list against one another to generate a similarity token between 0.01 to 1.00. Here's code
temp[]
start_node = 0
end_node = 0
length = len(temp)
for start_node in range(length):
doc1 = nlp(temp[start_node])
for end_node in range(++start_node, length):
doc2 = nlp(temp[end_node])
similar = doc1.similarity(doc2)
exp_value = float(0.85)
if similar == 1.0:
print("Exact match", similar, temp[end_node], "---------||---------", temp[start_node])
elif 0.96 < similar < 0.99:
print("possible match", similar, temp[end_node], "---------||---------", temp[start_node])
temp.remove(temp[end_node])
Here, I am trying to check one item with all others in the list if any items are similar then delete that item from the list as there is no benefit to check the similarity of sentences back again with other elements, that will be a waste of computing power. But when I am trying to pop out elements I am getting Out of index error.
<ipython-input-12-c1959947bdd1> in <module>
4 length = len(temp)
5 for start_node in range(length):
----> 6 doc1 = nlp(temp[start_node])
7 for end_node in range(++start_node, length):
8 doc2 = nlp(temp[end_node])
I am just trying to keep original sentences, delete all the sentences which are similar in list so it doesn't check back with those items.
Temp list have 351 items, here i am just referencing as a list.
here;s a test of it
print(temp[:1])
['malicious: caliche development partners "financial statement"has been shared with you']
I tried creating another duplicated list and delete similar items from that list
final_items = temp
start_node = 0
end_node = 0
length = len(temp)
for start_node in range(length):
doc1 = nlp(temp[start_node])
for end_node in range(++start_node, length):
doc2 = nlp(temp[end_node])
similar = doc1.similarity(doc2)
exp_value = float(0.85)
if similar == 1.0:
print("Exact match", similar, temp[end_node], "---------||---------", temp[start_node])
elif 0.96 < similar < 0.99:
print("possible match", similar, temp[end_node], "---------||---------", temp[start_node])
final_items.remove(temp[end_node])
But still got the same list index out of range while I am deleting elements from another list which I am not iterating even.