AI आपका सवाल समझे, essay लिखे, या sentence translate करे - इससे पहले उसे raw text process करना होता है। हर chatbot, search engine, और language model strings से शुरू होता है - characters की sequences जो human language represent करती हैं।
Strings समझना natural language processing का दरवाज़ा खोलता है - AI के सबसे exciting areas में से एक।
String characters की एक sequence है - letters, digits, spaces, symbols - order में stored।
message = "Hello, World!"
हर character की एक position (index) होती है, array जैसी:
index: 0 1 2 3 4 5 6 7 8 9 10 11 12
char: H e l l o , W o r l d !
Substring string का एक टुकड़ा है। "Hello, World!" से "World" (indices 7 से 11) extract कर सकते हो। AI systems लगातार substrings extract करते हैं - sentences से names, tweets से hashtags, web pages से URLs।
ज़्यादातर languages में strings immutable हैं - character in-place बदल नहीं सकते, नई string बनानी पड़ती है। Performance के लिए यह मायने रखता है: AI pipeline लाखों बार text modify करे तो हर बार नई string बनाना slow कर सकता है।
Shakespeare की पूरी रचनाओं में ~9 लाख शब्द हैं। GPT-4 हज़ारों गुना बड़े text datasets पर train हुआ - सैकड़ों अरब शब्द, सब strings के रूप में process हुए numbers में convert होने से पहले।
AI models शब्द इंसानों जैसे नहीं पढ़ते। वे tokenisation इस्तेमाल करते हैं - text को छोटे टुकड़ों (tokens) में तोड़ना।
Input: "unhappiness"
Tokens: ["un", "happiness"]
Input: "ChatGPT is brilliant"
Tokens: ["Chat", "G", "PT", " is", " brilliant"]
Tokenisation character-level और word-level processing के बीच है। Rare words को known sub-pieces में तोड़ता है, vocabulary manageable रखता है।
जब ChatGPT में "antidisestablishmentarianism" जैसा लंबा unusual word type करो, model इसे familiar sub-word tokens में तोड़ता है। हर possible English word को अलग token store करने से यह बेहतर क्यों है?
Sign in to join the discussion
Core string operation है text में pattern ढूँढना। क्या email में "urgent" शब्द है? क्या code में security vulnerability है?
Pattern text पर slide करो, character by character check करो:
text: "the cat sat on the mat"
pattern: "cat"
Position 0: "the" → no match
Position 1: "he " → no match
Position 4: "cat" → match found at index 4!
Worst case O(n × m) है जहाँ n text length और m pattern length। Short patterns के लिए ठीक है। Millions documents scan करने के लिए smarter approaches चाहिए।
बहुत बड़े texts पर naive pattern matching slow क्यों है?
String reverse करना simple है लेकिन data के बारे में सोच reveal करता है:
reverse("hello") → "olleh"
Palindrome आगे-पीछे से same पढ़ता है: "racecar", "madam", "level"।
is_palindrome(text):
return text == reverse(text)
दो words anagrams हैं अगर same characters अलग order में: "listen" और "silent"।
are_anagrams(word1, word2):
return character_counts(word1) == character_counts(word2)
Hash map से character frequencies count करो - O(n)।
दो words anagrams हैं, सबसे efficiently कैसे check करोगे?
Regex exact text की जगह patterns describe करने देता है:
| Pattern | Matches | Use Case |
|---------|---------|----------|
| \d+ | एक या ज़्यादा digits | Text से numbers extract |
| [A-Z][a-z]+ | Capitalised word | Proper nouns ढूँढना |
| \b\w+@\w+\.\w+\b | Email addresses | Data extraction |
| (cat\|dog\|bird) | तीनों में कोई भी | Classification keywords |
AI data pipelines regex extensively data cleaning में इस्तेमाल करती हैं - HTML tags हटाना, dates extract करना, phone numbers standardise करना।
Regex powerful है लेकिन tricky भी। Poorly written regex कुछ inputs पर exponentially लंबा चल सकता है - "catastrophic backtracking" कहते हैं। Edge cases पर patterns ज़रूर test करो।
AI text कैसे process करता है - simplified view:
हर step string operations involve करता है - slicing, searching, replacing, splitting।
जब किसी chatbot को ऐसी भाषा में message भेजो जहाँ शब्दों के बीच spaces नहीं होते (जैसे Chinese या Japanese), tokenisation अलग कैसे होगा? क्या extra challenges आएँगी?
OpenAI का tokeniser "tokenisation" को ["token", "isation"] - दो tokens में तोड़ता है। लेकिन American spelling "tokenization" ["token", "ization"] बनता है। Same concept, spelling बदली तो cost बदली!
Text processing pipeline में AI model को feed करने से पहले tokenisation क्यों किया जाता है?