Code Monkey home page Code Monkey logo

programming-language-classifier's Introduction

Programming Language Classifier

An example of how to use CreateML and Xcode 10 to train a CoreML model that is used by the Natural Language framework to classify the programming language of source code.

let code = """
struct Plane: Codable {
    var manufacturer: String
    var model: String
    var seats: Int
}
"""

let url = Bundle.main.url(forResource: "Classifier",
                          withExtension: "mlmodelc")!
let model = try! NLModel(contentsOf: url)
model.predictedLabel(for: code) // Swift

Requirements

  • macOS Mojave Beta
  • Xcode 10 Beta

These are available for Apple Developer account members to download at https://developer.apple.com/download/

Usage

This project includes a pre-trained programming language classifier model. To see it in action, open Classifier Demo.playground, run the playground with the Assistant editor showing the Live View, and then drag and drop a source code file. The model will predict the language of the file based on its contents.

Screenshot of Classifier Example

Training Instructions

  • Clone and setup the repository by running the following commands:
$ git clone https://github.com/flight-school/Programming-Language-Classifier.git`
$ cd Programming-Language-Classifier
$ git submodule update --init
  • Open Trainer.swift in an editor and fill in the placeholder values for destinationPath and corpusPath:
$ open ./Trainer.swift
  • Run Trainer.swift and wait for the model to be trained (on a 2017 MacBook Pro, this took a few minutes):
$ swift ./Trainer.swift
  • Compile the generated .mlmodel bundle using the following command:
$ xcrun coremlc compile path/to/ProgrammingLanguageClassifier.mlmodel .
  • Move the compiled .mlmodelc bundle into the Resources directory of Classifier Demo.playground, replacing any existing resource.

License

MIT

See code-corpora for licensing information of the included projects.

About Flight School

Flight School is a new book series for Swift developers. Each month, we'll explore an essential part of iOS, macOS, and Swift development through concise, focused books.

If you'd like to get in touch, feel free to message us on Twitter (@flightdotschool) or email us at mailto:[email protected].

programming-language-classifier's People

Contributors

mattt avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.