Skip to content

Instantly share code, notes, and snippets.

View ayushoriginal's full-sized avatar
😀
Looking for Full Time opportunities

Ayush Pareek ayushoriginal

😀
Looking for Full Time opportunities
View GitHub Profile
var okAlertController = UIAlertController.Create(title_text, body_text, UIAlertControllerStyle.Alert);
//Add Action
okAlertController.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null));
// Present Alert
PresentViewController(okAlertController, true, null);
nint[] ns_sum = new nint[] { 44, 1, 1 }; // 44 is the size of vocabulary
List<double> predicted_labels = new List<double>();
string hate_speech_var = "NOT OFFENSIVE";
double prob = 0.0;
MLMultiArray temp1 = new MLMultiArray(ns_sum, MLMultiArrayDataType.Double, out NSError error3);
var narray = new NSNumber[example.Length];
for (int i = 0; i < narray.Length; i++)
narray[i] = NSNumber.FromDouble(example[i]);
double[] example = new double[len_tweet];//Final Array automatically assigned to 0 at each index
int k = 0;
int m = 0;
string possible_key = null;
while (k < lemma_tokens_str.Count)
{
possible_key = lemma_tokens_str[k];
if (word_code.ContainsKey(possible_key))
{
int len_tweet = 0;
int size_vocab = 0;
// Tweet Length and Size of Vocab
foreach (var line in File.ReadLines("metadata_length_tweet_size_vocab.txt"))
{
string[] temp = line.Split(" ");
len_tweet = Convert.ToInt32(temp[0]);
size_vocab = Convert.ToInt32(temp[1]);
var currentDirectory = Directory.GetCurrentDirectory();
var dataFilePath = string.Format("{0}/{1}", currentDirectory, "full7z-mlteast-en.lem");
var stream = File.OpenRead(dataFilePath);
var lemmatizer = new Lemmatizer(stream); //Load Lemmatizer with the given dataFilePath
List<string> lemma_tokens_str = new List<string>();
List<string> stopword = new List<string>();
foreach (var line in File.ReadLines("stopword.txt"))
{
stopword.Add(line);
}
var stopword_set = new HashSet<string>(stopword); //Hashset of Stopwords
// Let t_tokens_str be the tokenized version of the string
@ayushoriginal
ayushoriginal / nltk_stopwords.py
Last active June 24, 2019 12:19
nltk_stopwords
import nltk
from nltk.corpus import stopwords
s=set(stopwords.words('english'))
@ayushoriginal
ayushoriginal / token_lowercase_cs.cs
Last active June 24, 2019 11:56
token_lowercase_cs
using NaturalLanguage;
private readonly hate_coreml hate_model = new hate_coreml(); // Initialize CoreML Model
NSValue[] tokens;
var tokenizer = new NLTokenizer(unit);
tokenizer.String = UserInput.Text;
var range = new NSRange(0, UserInput.Text.Length);
var k = tokenizer.GetTokens(range); // returns Foundation.NSValue[]
# Let the keras model be 'model'
# OPTION 1: Convert Keras model to ONNX and convert ONNX model to CoreML model
import onnxmltools
onnx_model = onnxmltools.convert_keras(model) #Keras to ONNX
from onnx_coreml import convert
mlmodel = convert(onnx_model) # ONNX to CoreML
mlmodel.save('hate_coreml_model.mlmodel')
def LSTM(self):
model = Sequential()
model.add(Embedding(self.vocab_length, 30, input_length=self.max_len))
model.add(LSTM(200))
model.add(Dense(self.max_len, activation='relu', W_regularizer=l2(0.90)))
model.add(Dense(self.tr_labels.shape[1], activation='softmax', W_regularizer=l2(0.1)))
adam_1 = Adam(lr=0.008)
model.compile(loss='categorical_crossentropy', optimizer=adam_1,metrics=['accuracy'])
model.summary()
self.model = model