Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
M

Member 8054321

@Member 8054321
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • SQL Injection Detection
    M Member 8054321

    Please help make this code work. I'm trying to run it in Visual Studio 2022. Thanks.

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using Numpy;
    using Python.Runtime;
    using Keras;
    using Keras.Layers;
    using Keras.Models;
    using Keras.Optimizers;
    using Keras.losses;

    namespace SQLInjectionDetection
    {
    class Program
    {
    static void Main(string[] args)
    {
    // Load CSV file
    var trainData = File.ReadAllLines("tokens.csv")
    .Select(l => l.Split(','))
    .Select(s => new { Token = s[0], Label = int.Parse(s[1]) })
    .ToList();

            // Shuffle trainData
            var random = new Random();
            trainData = trainData.OrderBy(d => random.Next()).ToList();
    
            // Split trainData into training and validation sets
            var splitIndex = (int)(trainData.Count \* 0.8);
            var trainDataSubset = trainData.Take(splitIndex).ToList();
            var testDataSubset = trainData.Skip(splitIndex).ToList();
    
            // Define vocabulary and tokenize trainData
            var vocabulary = new HashSet(trainDataSubset.SelectMany(d => d.Token).Distinct());
            var tokenToIndex = vocabulary.Select((c, i) => new { Token = c, Index = i }).ToDictionary(t => t.Token, t => t.Index);
            var maxSequenceLength = trainDataSubset.Max(d => d.Token.Length);
            var trainTokenized = Tokenize(trainDataSubset, tokenToIndex, maxSequenceLength);
            var testTokenized = Tokenize(testDataSubset, tokenToIndex, maxSequenceLength);
    
            // Build RNN model
            using (Py.GIL())
            {
                dynamic keras = Py.Import("keras");
                dynamic np = Py.Import("numpy");
                var input = new Input(shape: 1000);
                var embedding = new Embedding(vocabulary.Count, 32).Apply(input);
                var lstm = new LSTM(32).Apply(embedding);
                var output = new Dense(1, activation: keras.activations.sigmoid).Apply(lstm);
                var model = new Model(inputs: input, outputs: output);
                model.Compile(optimizer: new Adam(), loss: new BinaryCrossentropy(), metrics: new\[\] { "accuracy" });
    
                // Train model
                var trainX = trainTokenized.Item1;
                var trainY = trainTokenized.Item2;
                var testX = testTokenized.Item1;
    
    C# csharp python database visual-studio linq
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups