Views
No views yet
python -m pip install -U angle-emb1from scipy import spatial
2from angle_emb import AnglE
3
4model = AnglE.from_pretrained('SeanLee97/UAE-GIS-Large-V1').cuda()
5
6quick_sort = '''# Approach 2: Quicksort using list comprehension
7
8def quicksort(arr):
9 if len(arr) <= 1:
10 return arr
11 else:
12 pivot = arr[0]
13 left = [x for x in arr[1:] if x < pivot]
14 right = [x for x in arr[1:] if x >= pivot]
15 return quicksort(left) + [pivot] + quicksort(right)
16
17# Example usage
18arr = [1, 7, 4, 1, 10, 9, -2]
19sorted_arr = quicksort(arr)
20print("Sorted Array in Ascending Order:")
21print(sorted_arr)'''
22
23
24bubble_sort = '''def bubblesort(elements):
25 # Looping from size of array from last index[-1] to index [0]
26 for n in range(len(elements)-1, 0, -1):
27 swapped = False
28 for i in range(n):
29 if elements[i] > elements[i + 1]:
30 swapped = True
31 # swapping data if the element is less than next element in the array
32 elements[i], elements[i + 1] = elements[i + 1], elements[i]
33 if not swapped:
34 # exiting the function if we didn't make a single swap
35 # meaning that the array is already sorted.
36 return
37
38elements = [39, 12, 18, 85, 72, 10, 2, 18]
39
40print("Unsorted list is,")
41print(elements)
42bubblesort(elements)
43print("Sorted Array is, ")
44print(elements)'''
45
46vecs = model.encode([
47 'def echo(): print("hello world")',
48 quick_sort,
49 bubble_sort
50])
51
52
53print('cos sim (0, 1):', 1 - spatial.distance.cosine(vecs[0], vecs[1]))
54print('cos sim (0, 2)', 1 - spatial.distance.cosine(vecs[0], vecs[2]))
55print('cos sim (1, 2):', 1 - spatial.distance.cosine(vecs[1], vecs[2]))
56cos sim (0, 1): 0.34329649806022644
cos sim (0, 2) 0.3627094626426697
cos sim (1, 2): 0.69722193479537961@article{li2023angle,
2 title={AnglE-optimized Text Embeddings},
3 author={Li, Xianming and Li, Jing},
4 journal={arXiv preprint arXiv:2309.12871},
5 year={2023}
6}