YuNotes Technical Blog

website·Indexed 30 days ago

https://moyu-moyuing.github.io/YuNotes/

A technical knowledge base and blog covering a wide range of topics including C++ basics, JavaScript and TypeScript fundamentals, Web APIs, Machine Learning overviews, and AI research. It also features practical guides on tools like Git, Obsidian, VitePress, and InternLM environment configuration, as well as development records for knowledge graph visualization and NER annotation tools.

Tokens
15.8K
Snippets
84
Records
102
Agent score
75%

What's inside YuNotes

  1. Overview of InternLM Open Source Ecosystem

    The InternLM (书生·浦语) open-source ecosystem provides a full-link suite of tools for large language model development, covering the entire pipeline from data preparation to deployment and application. The core components include:

    • InternEvo: Used for model pre-training.
    • XTuner: Used for model fine-tuning.
    • OpenCompass: Used for model evaluation.
    • LMDeploy: Used for model deployment.
    • Lagent: A framework for building intelligent agents.
    • 茴香豆 (Huixiangdou): A tool/framework for Retrieval-Augmented Generation (RAG).
  2. Understand Machine Learning basics and types

    Machine Learning is defined as a computer program that learns from experience (E) to solve a task (T) with a performance measure (P), where performance at the task improves with experience.

    There are two primary types of learning:

    1. Supervised Learning: The algorithm is provided with a dataset containing correct answers (labels). The goal is to predict correct answers for new data. This is further divided into:
      • Regression: Predicting a continuous numerical output (e.g., predicting house prices).
      • Classification: Predicting a discrete numerical output or category (e.g., predicting if a tumor is benign or malignant).
    2. Unsupervised Learning: The algorithm is given a dataset without correct answers and must find patterns or structures on its own. A common application is Clustering (e.g., Google News grouping similar articles, market segmentation, or genomic analysis).
  3. Perform type conversion in JavaScript

    JavaScript performs both implicit and explicit type conversion.

    Implicit Conversion:

    • The + operator converts operands to strings if one is a string.
    • Other operators (like -, *, /) typically convert operands to numbers.
    • null converts to 0, undefined converts to NaN during numeric conversion.

    Explicit Conversion:

    • Number(value): Converts to a number; returns NaN if conversion fails.
    • parseInt(value): Converts to an integer.
    • parseFloat(value): Converts to a floating-point number.

    Falsy Values: The following values are treated as false in boolean contexts: '', 0, undefined, null, false, and NaN. All other values are true.

    // Implicit
    console.log("" + 1); // "1"
    console.log(null + 1); // 1
    
    // Explicit
    let strNum = "123.45";
    console.log(Number(strNum));   // 123.45
    console.log(parseInt(strNum)); // 123
    console.log(parseFloat(strNum)); // 123.45
  4. Handle Class Inheritance and Interface Implementation

    Classes can inherit behavior using extends (class-to-class) or enforce a structure using implements (class-to-interface).
    // Class Inheritance
    class Animal {
        move() { console.log('moving'); }
    }
    class Dog extends Animal {
        bark() { console.log('woof'); }
    }
    
    // Interface Implementation
    interface Singable {
        sing(): void;
        name: string;
    }
    class Person implements Singable {
        name = 'Zhang San';
        sing() { console.log('singing...'); }
    }
  5. Create new types using Mapped Types

    Mapped types allow you to create new object types based on a union of keys, reducing repetition. They use the [Key in Union] syntax. Note: Mapped types can only be used in type aliases (type), not in interfaces.
    type PropKeys = 'x' | 'y' | 'z';
    
    // Creates a type where x, y, and z are all numbers
    type Type2 = { [Key in PropKeys]: number };
    
    // ERROR: Mapped types are not allowed in interfaces
    // interface Type3 { [Key in PropKeys]: number; }
  6. Configure Husky to enforce commit message linting

    Husky allows you to trigger the commit-msg git hook to run CommitLint before a commit is finalized. If the commit message does not meet the specified rules, the commit will be aborted.
    # 1. Install husky
    npm install husky --save-dev
    
    # 2. Initialize husky (creates .husky directory)
    npm set-script prepare "husky install"
    npm run prepare
    
    # 3. Add the commit-msg hook
    # For Linux/macOS:
    npx husky add .husky/commit-msg "npx --no -- commitlint --edit ${1}"
    
    # For Windows (Manual approach if the above fails):
    # First, create the file:
    npx husky add .husky/commit-msg
    # Then, manually edit .husky/commit-msg and add the following line:
    npx --no -- commitlint --edit
  7. Embed JavaScript in HTML

    JavaScript must be embedded in HTML to be executed by the browser using the <script> tag. There are three primary methods:

    1. Internal: Code is written directly inside <script> tags. It is recommended to place these tags at the bottom of the <body> to ensure HTML elements are loaded before the script attempts to modify them.
    2. External: Code is written in a .js file and linked via the src attribute. This improves code organization and reusability.
    3. Inline: Code is written directly within HTML attribute event handlers (e.g., onclick).

    <!-- External Method --> <body> <script src="my.js"></script> </body>

    <!-- Inline Method --> <body> <button onclick="alert('Hello')">Click Me</button> </body>

  8. Define types with Index Signatures

    Index signatures are used when the exact property names of an object are unknown or when an object can have an arbitrary number of properties. This is defined using the [key: type] syntax within an interface.
    // Object with any string key and number value
    interface AnyObject {
        [key: string]: number;
    }
    let obj: AnyObject = { a: 1, b: 2 };
    
    // Array-like interface with number index
    interface MyArray<T> {
        [n: number]: T;
    }
    let arr: MyArray<number> = [1, 3, 5];
  9. Deploy InternLM2 with a Streamlit Web Demo

    To provide a web-based user interface for InternLM2, clone the official InternLM Tutorial repository and run the provided Streamlit demo script.
    cd /root/modeldemo
    git clone https://github.com/InternLM/Tutorial.git
    
    # Start the Streamlit server
    cd /root/demo
    streamlit run /root/modeldemo/Tutorial/tools/streamlit_demo.py --server.address 127.0.0.1 --server.port 6006
  10. Create and manipulate objects in JavaScript

    Objects are collections of properties (key-value pairs) and methods (functions). Properties can be accessed via dot notation (obj.prop) or bracket notation (obj['prop']). Bracket notation is required when property names contain special characters (like hyphens). Use the delete operator to remove a property.
    // Declaration
    let person = {
        name: 'zhang',
        age: 18,
        sayHello: function() {
            console.log('Hello');
        }
    };
    
    // Access and Modification
    console.log(person.name);          // Dot notation
    person['name'] = 'lisi';            // Assignment
    person.city = 'Beijing';            // Adding new property
    delete person.age;                 // Deleting property
    person.sayHello();                 // Calling method
  11. Install and configure CommitLint

    CommitLint is a tool used to verify that git commit messages follow a specific format. To set it up, install the CLI and the conventional configuration package, then create a configuration file.
    # Install CLI and conventional config
    npm install --save-dev @commitlint/config-conventional @commitlint/cli
    
    # Create commitlint.config.js
    echo "module.exports = {extends: ['@commitlint/config-conventional']};" > commitlint.config.js