This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nltk | |
from nltk.corpus import stopwords | |
s=set(stopwords.words('english')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
NewerOlder