sentence-transformers How to use Nan-Do/CP-Ranker with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("Nan-Do/CP-Ranker", trust_remote_code=True)
sentences = [
"Swaps in a String\nYou are given a string $S$ that contains of the characters $A$, $B$ or $C$ only.\n\nIn one operation, you can do either of the following:\n\n- Choose an occurrence of $\\text{AB}$ in the string, convert it to $\\text{BA}$.\n- Choose an occurrence of $\\text{BC}$ in the string, convert it to $\\text{CB}$.\n\nNote that you are only allowed to operate on adjacent elements.\n\nFind the maximum number of operations you can do. It can be proven the answer is finite.\n\nInput Format:\n- The first line of input will contain a single integer $T$, denoting the number of test cases.\n- Each test case consists of multiple lines of input.\n - The first line of each test case contains $N$ - the length of the string.\n - The second line contains $S$ - the string.\n\nOutput Format:\nFor each test case, output on a new line the maximum number of operations possible.\n\nConstraints:\n- $1 \\le T \\le 10^4$\n- $2 \\le N \\le 2 \\cdot 10^5$\n- $|S| = N$\n- $S_i \\in \\{A, B, C\\}$\n- The sum of $N$ over all test cases does not exceed $2 \\cdot 10^5$.\n\nSample 1:\nInput:\n3\n4\nABCC\n5\nBAABB\n2\nBA\n\nOutput:\n2\n4\n0\nExplanation:\n**Test Case 1** : We can convert $\\text{ABCC}$ to $\\text{ACBC}$ and then to $\\text{ACCB}$. More than $2$ operations can be proven to be impossible.\n\n**Test Case 2** : $\\text{BAABB} \\rightarrow \\text{BABAB} \\rightarrow \\text{BBAAB} \\rightarrow \\text{BBABA} \\rightarrow \\text{BBBAA}$.\n",
"#from collections import Counter\r\n#import math\r\n#import deque\r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n a=input()\r\n C1=[]\r\n C2=[]\r\n c1=0\r\n c2=0\r\n res=0\r\n for i in a:\r\n if i=='A':\r\n c1+=1\r\n elif i=='B':\r\n pass\r\n else:\r\n c1=0\r\n C1.append(c1)\r\n for i in a[::-1]:\r\n if i=='A':\r\n c2=0\r\n elif i=='B':\r\n pass\r\n else:\r\n c2+=1\r\n C2.append(c2)\r\n C2=C2[::-1]\r\n for i in range(n):\r\n if a[i]=='B':\r\n res+=max(C1[i],C2[i])\r\n print(res)",
"#from collections import Counter\r\n#import math\r\n#import deque\r\nt=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n a=input()\r\n C1=[]\r\n C2=[]\r\n c1=0\r\n c2=0\r\n res=0\r\n for i in a:\r\n if i=='A':\r\n c1+=1\r\n elif i=='C':\r\n c1=0\r\n C1.append(c1)\r\n for i in a[::-1]:\r\n if i=='A':\r\n c2=0\r\n elif i=='C':\r\n c2+=1\r\n C2.append(c2)\r\n C2=C2[::-1]\r\n for i in range(n):\r\n if a[i]=='B':\r\n res+=max(C1[i],C2[i])\r\n print(res)",
"# cook your dish here\r\nimport math\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n x=math.ceil(n/2)\r\n y=math.ceil(n/3)\r\n print(x,y)\r\n "
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]