sentence-transformers How to use buelfhood/SOCO-Java-CodeBERTa-MNRL-Triplets-100 with sentence-transformers:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("buelfhood/SOCO-Java-CodeBERTa-MNRL-Triplets-100")
sentences = [
"\n\nimport java.net.*;\nimport java.io.*;\n\npublic class sendMail {\n\npublic void sendMail(String mailServer, String recipient, String result) {\n try {\n Socket s = new Socket(mailServer, 25);\n BufferedReader in = new BufferedReader\n (new InputStreamReader(s.getInputStream(), \"8859_1\"));\n BufferedWriter out = new BufferedWriter\n (new OutputStreamWriter(s.getOutputStream(), \"8859_1\"));\n\n send(in, out, \"HELO client\");\n\n send(in, out, \"MAIL FROM: <WatchDog@SecureECommerce.>\");\n send(in, out, \"RCPT : \" + recipient);\n send(in, out, \"DATA\");\n send(out, \"Subject: \");\n send(out, \"From: Admin <WatchDog@SecureECommerce.>\");\n send (out, \"\\n\");\n \n send(out, result);\n send(out, \"\\n.\\n\");\n send(in, out, \"QUIT\");\n\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedReader in, BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n s = in.readLine();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n}",
"import java.net.*;\nimport java.io.*;\nimport java.*;\n\n public class BruteForce {\n\n URLConnection conn = null;\n private static boolean status = false;\n\n public static void main (String args[]){\n BruteForce a = new BruteForce();\n String[] inp = {\"http://sec-crack.cs.rmit.edu./SEC/2/index.php\",\n \t\t\t\t \"\",\n \t\t\t\t \"\"};\n int attempts = 0;\n exit:\n for (int i=0;i<pwdArray.length;i++) {\n\t\t for (int j=0;j<pwdArray.length;j++) {\n\t\t\t for (int k=0;k<pwdArray.length;k++) {\n\t\t\t\t if (pwdArray[i] == ' ' && pwdArray[j] != ' ') continue;\n\t\t\t\t if (pwdArray[j] == ' ' && pwdArray[k] != ' ') continue;\n\t\t\t\t inp[2] = inp[2] + pwdArray[i] + pwdArray[j] + pwdArray[k];\n\t\t\t\t attempts++;\n \t\t\t a.doit(inp);\n \n \t\t\t\t if (status) {\n\t\t\t\t\t System.out.println(\"Crrect password is: \" + inp[2]);\n\t\t\t\t\t System.out.println(\"Number of attempts = \" + attempts);\n\t\t\t\t\t break exit;\n\t\t\t \t }\n \t\t\t inp[2] = \"\";\n\t\t \t }\n\t \t }\n }\n }\n\n public void doit(String args[]) {\n \n try {\n BufferedReader in = new BufferedReader(\n new InputStreamReader\n (connectURL(new URL(args[0]), args[1], args[2])));\n String line;\n while ((line = in.readLine()) != null) {\n System.out.println(line);\n status = true;\n }\n }\n catch (IOException e) {\n \n }\n }\n\n public InputStream connectURL (URL url, String uname, String pword)\n throws IOException {\n conn = url.openConnection();\n conn.setRequestProperty (\"Authorization\",\n userNamePasswordBase64(uname,pword));\n conn.connect ();\n return conn.getInputStream();\n }\n\n public String userNamePasswordBase64(String username, String password) {\n return \" \" + base64Encode (username + \":\" + password);\n }\n\n private final static char pwdArray [] = {\n\t 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',\n\t 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',\n\t 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',\n\t 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F',\n\t 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',\n\t 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',\n\t 'W', 'X', 'Y', 'Z', ' '\n };\n\n private final static char base64Array [] = {\n 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',\n 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',\n 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',\n 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',\n 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',\n 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',\n 'w', 'x', 'y', 'z', '0', '1', '2', '3',\n '4', '5', '6', '7', '8', '9', '+', '/'\n };\n\n private static String base64Encode (String string) {\n String encodedString = \"\";\n byte bytes [] = string.getBytes ();\n int i = 0;\n int pad = 0;\n while (i < bytes.length) {\n byte b1 = bytes [i++];\n byte b2;\n byte b3;\n if (i >= bytes.length) {\n b2 = 0;\n b3 = 0;\n pad = 2;\n }\n else {\n b2 = bytes [i++];\n if (i >= bytes.length) {\n b3 = 0;\n pad = 1;\n }\n else\n b3 = bytes [i++];\n }\n byte c1 = (byte)(b1 >> 2);\n byte c2 = (byte)(((b1 & 0x3) << 4) | (b2 >> 4));\n byte c3 = (byte)(((b2 & 0xf) << 2) | (b3 >> 6));\n byte c4 = (byte)(b3 & 0x3f);\n encodedString += base64Array [c1];\n encodedString += base64Array [c2];\n switch (pad) {\n case 0:\n encodedString += base64Array [c3];\n encodedString += base64Array [c4];\n break;\n case 1:\n encodedString += base64Array [c3];\n encodedString += \"=\";\n break;\n case 2:\n encodedString += \"==\";\n break;\n }\n }\n return encodedString;\n }\n }\n\n",
"\nimport java.io.*;\n\npublic class PasswordFile {\n \n private String strFilepath;\n private String strCurrWord;\n private File fWordFile;\n private BufferedReader in;\n \n \n public PasswordFile(String filepath) {\n strFilepath = filepath;\n try {\n fWordFile = new File(strFilepath);\n in = new BufferedReader(new FileReader(fWordFile));\n }\n catch(Exception e)\n {\n System.out.println(\"Could not open file \" + strFilepath);\n }\n }\n \n String getPassword() {\n return strCurrWord;\n }\n \n String getNextPassword() {\n try {\n strCurrWord = in.readLine();\n \n \n \n }\n catch (Exception e)\n {\n \n return null;\n }\n \n return strCurrWord;\n }\n \n}\n",
"\n\nimport java.net.*;\nimport java.io.*;\n\npublic class SendEMail {\n\n public void SendEMail(){}\n\npublic void sendMail(String recipient,String c, String subject){\n try {\n\n Socket s = new Socket(\"yallara.cs.rmit.edu.\", 25);\n BufferedReader in = new BufferedReader\n (new InputStreamReader(s.getInputStream(), \"8859_1\"));\n BufferedWriter out = new BufferedWriter\n (new OutputStreamWriter(s.getOutputStream(), \"8859_1\"));\n\n send(in, out, \"HELO theWorld\");\n \n \n send(in, out, \"MAIL FROM: <watch@dog.>\");\n send(in, out, \"RCPT : \"+recipient);\n send(in, out, \"DATA\");\n send(out, \"Subject: \"+ subject);\n send(out, \"From: WatchDog.java\");\n send (out, \"\\n\");\n \n BufferedReader reader;\n String line;\n reader = new BufferedReader(new InputStreamReader(new FileInputStream()));\n line = reader.readLine();\n while (line != null){\n send(out, line);\n line = reader.readLine();\n }\n send(out, \"\\n.\\n\");\n send(in, out, \"QUIT\");\n s.print();\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedReader in, BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n s = in.readLine();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n\n public void send(BufferedWriter out, String s) {\n try {\n out.write(s + \"\\n\");\n out.flush();\n System.out.println(s);\n }\n catch (Exception e) {\n e.printStackTrace();\n }\n }\n}"
]
embeddings = model.encode(sentences)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
# [4, 4]