今日已更新 222 条资讯 | 累计 40667 条内容
关于我们

标签:#100daysofcode

找到 2 篇相关文章

AI 资讯

Day 4: Bag-of-Words and Text Vectorization

Previously, on Day 3: Explained stopword removal, stemming, and lemmatization in NLP, including how they simplify and normalize text for analysis using practical examples and Python code. Text Vectorization: Turning Words into Numbers Computers work with numbers, not text. To handle language, a Natural Language Processing (NLP) system must convert words, sentences, or documents into numerical data. Usually, this means turning them into vectors—ordered arrays of numbers. This process is called text vectorization . A vector is a mathematical summary of a piece of text. The details and meaning behind the numbers depend on which vectorization method is used, but all serve a common purpose: to translate language into something a machine can process. For example, imagine building a program to filter spam emails. The program can't directly understand words like "WINNER" or "sale." Every word must be mapped to a number before the program can look for patterns in messages. What is the Bag-of-Words Model? Bag-of-Words (BoW) is the simplest and most common way to vectorize text. BoW ignores grammar and word order. It treats each document as a "bag" containing words, just counting how many times each word appears. For example, the sentences "dog bites man" and "man bites dog" will produce the same vector in a BoW system. Both have the words "dog," "bites," and "man," each once. The meaning is very different to a human, but to BoW, they're identical. This straightforward approach makes BoW fast and effective for many tasks, especially where quickly spotting key words is enough—for example, spam detection. From Words to Vectors: Building a Vocabulary The first step in BoW is to build a vocabulary . This is a list of all unique words seen across your dataset (called a "corpus"). Suppose your dataset contains two sentences: "cat sat on the mat" "dog sat on the log" List all unique words: ["cat", "sat", "on", "the", "mat", "dog", "log"] The word order in the vocabulary doesn't matte

2026-08-28 原文 →
开发者

Python Fundamentals for a JavaScript Developer

I'll guide you through Python fundamentals by comparing concepts with JavaScript. Let's start! 1. Hello World & Basic Syntax JavaScript console . log ( " Hello World " ); let x = 5 ; Python print ( " Hello World " ) x = 5 # No semicolon, no let/const Key Differences: No semicolons in Python Indentation matters (replaces curly braces) Comments use # instead of // 2. Variables & Data Types JavaScript let name = " Alice " ; // string let age = 30 ; // number let isStudent = true ; // boolean let scores = [ 95 , 87 , 91 ]; // array let person = { // object name : " Bob " , age : 25 }; let nothing = null ; let notDefined = undefined ; Python name = " Alice " # str age = 30 # int (or float for decimals) is_student = True # bool (capital T/F) scores = [ 95 , 87 , 91 ] # list (mutable) person = { # dict (dictionary) " name " : " Bob " , " age " : 25 } nothing = None # Python's null/undefined Key Differences: Python uses snake_case (not camelCase) True / False capitalized None instead of null / undefined Lists ≈ Arrays, Dicts ≈ Objects 3. Control Flow JavaScript // If-else if ( age >= 18 ) { console . log ( " Adult " ); } else if ( age >= 13 ) { console . log ( " Teen " ); } else { console . log ( " Child " ); } // For loop for ( let i = 0 ; i < 5 ; i ++ ) { console . log ( i ); } // While loop let count = 0 ; while ( count < 5 ) { console . log ( count ); count ++ ; } Python # If-else (indentation instead of braces) if age >= 18 : print ( " Adult " ) elif age >= 13 : # NOT else if print ( " Teen " ) else : print ( " Child " ) # For loop (more like for...of in JS) for i in range ( 5 ): # range(5) = [0, 1, 2, 3, 4] print ( i ) # Iterate over list (like for...of) for score in scores : print ( score ) # While loop count = 0 while count < 5 : print ( count ) count += 1 # No ++ operator in Python 4. Functions JavaScript // Function declaration function add ( a , b ) { return a + b ; } // Arrow function const multiply = ( a , b ) => a * b ; // Default parameters function greet ( n

2026-07-23 原文 →