Wednesday, October 16, 2024

Deep Learning with NLP Laboratory Btech sem 7 [203105477] Parul University



1. Implementation of Text Preprocessing with NLTK

Tokenization, Stemming, Lemmatization, and Removal of Stopwords:


import nltk from nltk.tokenize import word_tokenize from nltk.corpus import stopwords from nltk.stem import PorterStemmer, WordNetLemmatizer nltk.download('punkt') nltk.download('stopwords') nltk.download('wordnet') # Sample text text = "NLTK is a powerful library for text preprocessing in NLP tasks." # Tokenization tokens = word_tokenize(text) # Stemming stemmer = PorterStemmer() stemmed_words = [stemmer.stem(word) for word in tokens] # Lemmatization lemmatizer = WordNetLemmatizer() lemmatized_words = [lemmatizer.lemmatize(word) for word in tokens] # Removing Stopwords stop_words = set(stopwords.words('english')) filtered_words = [word for word in tokens if word.lower() not in stop_words] print("Tokens:", tokens) print("Stemmed Words:", stemmed_words) print("Lemmatized Words:", lemmatized_words) print("Filtered Words:", filtered_words)

2. Convert Text to Word Count Vectors with Scikit-Learn

Using CountVectorizer:


from sklearn.feature_extraction.text import CountVectorizer # Sample text data corpus = [ 'This is the first document.', 'This document is the second document.', 'And this is the third one.', 'Is this the first document?' ] vectorizer = CountVectorizer() X = vectorizer.fit_transform(corpus) print("Feature Names:", vectorizer.get_feature_names_out()) print("Word Count Vectors:\n", X.toarray())

3. Convert Text to Word Frequency Vectors with Scikit-Learn

Using TfidfVectorizer:


from sklearn.feature_extraction.text import TfidfVectorizer corpus = [ 'This is the first document.', 'This document is the second document.', 'And this is the third one.', 'Is this the first document?' ] tfidf_vectorizer = TfidfVectorizer() X_tfidf = tfidf_vectorizer.fit_transform(corpus) print("TF-IDF Feature Names:", tfidf_vectorizer.get_feature_names_out()) print("TF-IDF Vectors:\n", X_tfidf.toarray())

4. Convert Text to Unique Integers with Scikit-Learn

Using HashingVectorizer:


from sklearn.feature_extraction.text import HashingVectorizer corpus = [ 'This is the first document.', 'This document is the second document.', 'And this is the third one.', 'Is this the first document?' ] hashing_vectorizer = HashingVectorizer(n_features=10) X_hash = hashing_vectorizer.fit_transform(corpus) print("Hashing Vectors:\n", X_hash.toarray())

5. Using Keras to Split Words

Using text_to_word_sequence:


from keras.preprocessing.text import text_to_word_sequence # Sample text text = "Keras is a powerful deep learning library." # Split words words = text_to_word_sequence(text) print("Words:", words)

6. Encoding with Keras one_hot


from keras.preprocessing.text import one_hot # Sample text text = "Keras is a great library for deep learning." # Vocabulary size vocab_size = 50 # One-hot encode encoded_words = one_hot(text, vocab_size) print("Encoded words:", encoded_words)

7. Hash Encoding with Keras hashing_trick


from keras.preprocessing.text import hashing_trick # Sample text text = "Keras is an amazing library for NLP." # Hash Encoding vocab_size = 50 hashed_words = hashing_trick(text, vocab_size, hash_function='md5') print("Hashed words:", hashed_words)

8. Demo of Keras Tokenizer API


from keras.preprocessing.text import Tokenizer # Sample corpus corpus = [ 'Keras is a deep learning library.', 'It helps in NLP and other machine learning tasks.', 'We are learning text processing with Keras.' ] # Tokenization tokenizer = Tokenizer() tokenizer.fit_on_texts(corpus) # Word index word_index = tokenizer.word_index print("Word Index:", word_index) # Convert to sequences sequences = tokenizer.texts_to_sequences(corpus) print("Text Sequences:", sequences)

9. Sentiment Analysis Experiment

You can perform sentiment analysis on a dataset like Twitter tweets or movie reviews. Here's an example using the nltk movie_reviews dataset:


import nltk from nltk.corpus import movie_reviews from nltk.classify import NaiveBayesClassifier from nltk.classify.util import accuracy nltk.download('movie_reviews') # Extract features def extract_features(words): return {word: True for word in words} # Prepare data positive_reviews = [(extract_features(movie_reviews.words(fileid)), 'pos') for fileid in movie_reviews.fileids('pos')] negative_reviews = [(extract_features(movie_reviews.words(fileid)), 'neg') for fileid in movie_reviews.fileids('neg')] # Split dataset into training and testing train_data = positive_reviews[:800] + negative_reviews[:800] test_data = positive_reviews[800:] + negative_reviews[800:] # Train Naive Bayes classifier classifier = NaiveBayesClassifier.train(train_data) # Evaluate print("Accuracy:", accuracy(classifier, test_data)) # Show most informative features classifier.show_most_informative_features(10)

10. Word2Vec Embedding with Gensim


from gensim.models import Word2Vec # Sample sentences sentences = [ ['this', 'is', 'the', 'first', 'sentence'], ['this', 'is', 'another', 'sentence'], ['word2vec', 'is', 'cool'] ] # Train Word2Vec model model = Word2Vec(sentences, vector_size=100, window=5, min_count=1, workers=4) # Check word vector vector = model.wv['sentence'] print("Vector for 'sentence':", vector) # Check most similar words similar_words = model.wv.most_similar('sentence') print("Most similar to 'sentence':", similar_words)

Wednesday, October 9, 2024

History of C Programming Language

 

Introduction to the C Language

The C programming language has been a cornerstone of computer science for decades. Its simplicity and efficiency have made it one of the most widely used languages in the world. From operating systems to embedded systems, C is everywhere.

Have you ever wondered how this powerful language came into existence? Or what makes it stand out from its counterparts? Whether you're a seasoned programmer or just starting your coding journey, understanding the history of C can deepen your appreciation for its design and functionality.

Join us as we explore the fascinating evolution of the C programming language, uncovering its roots and significance along the way. You might find that there's more to C than meets the eye!

The Development of C

The C programming language emerged in the early 1970s, crafted by Dennis Ritchie at Bell Labs. It was born out of necessity to improve upon B, an earlier language that struggled with system-level programming.

Ritchie's work coincided with the development of Unix. C became the go-to language for writing operating systems and utilities. Its syntax drew inspiration from both B and BCPL, making it more powerful yet simpler.

With its flexible structure and efficiency, C rapidly gained popularity among programmers. By 1978, Brian Kernighan and Ritchie published "The C Programming Language," which solidified its status as a vital tool for developers everywhere.

As technology evolved, so did C. The ANSI standardization in 1989 updated it for modern computing needs while maintaining backward compatibility. This evolution ensured that programmers could rely on it across various platforms without losing functionality or performance.

Key Features and Benefits of C

The C programming language is renowned for its efficiency and flexibility. One of its standout features is low-level access to memory, allowing developers to manipulate hardware directly. This capability makes it an ideal choice for system programming.

Another significant benefit of C is its portability. Code written in C can be compiled on various platforms with minimal modifications, making it versatile across different operating systems.

C also boasts a rich set of operators and data types, enabling precise control over program behavior. Its structured approach promotes clean code organization and enhances readability.

The extensive library support available means that developers can tap into pre-existing functions, speeding up the development process while ensuring reliability. These attributes have solidified C's place as a foundational language in computer science education and software development.

Comparison with Other Programming Languages

The C programming language stands out in the crowded landscape of coding languages. Its efficiency and performance are often unmatched, making it a preferred choice for system-level programming.

When compared to higher-level languages like Python or Ruby, C offers greater control over hardware resources. This is crucial for applications that require speed and optimized memory usage.

Languages such as Java introduce additional layers with their virtual machine, which can slow down execution time. In contrast, C compiles directly to machine code, allowing programs to run faster on various platforms.

Moreover, while modern languages often prioritize ease of use and abstraction, C demands a deeper understanding of how computers work. This foundational knowledge can be invaluable for programmers transitioning into more complex environments later on.

Famous Programs Written in C

The C programming language has been the backbone of many influential software applications. One notable example is the operating system Unix, which was primarily developed in C in the late 1960s and early 1970s. Its portability and efficiency revolutionized how developers approached operating systems.

Another landmark program written in C is the GNU Compiler Collection (GCC). This powerful toolchain compiles code for various programming languages, making it a crucial resource for developers worldwide.

Additionally, major databases like MySQL owe their existence to C. Its ability to handle low-level data manipulation makes it ideal for performance-critical applications.

Even today, much of modern software relies on libraries or components initially crafted in C. Its enduring influence can be seen across countless fields—from embedded systems to high-performance computing environments.

Future of C and its Relevance Today

The C programming language continues to hold a significant place in the world of software development. Despite newer languages emerging, C remains foundational, influencing many modern languages like C++, Java, and Python.

Its efficiency makes it ideal for system-level programming. Operating systems, embedded systems, and performance-critical applications still rely heavily on C. This reliability ensures that skills in this language remain highly sought after.

With the rise of IoT (Internet of Things), C is becoming increasingly relevant again. Many microcontrollers use C due to its close-to-hardware nature and minimal overhead.

Educational institutions also emphasize learning C as a first programming language. It fosters a deep understanding of computer fundamentals. As technology evolves, so does the need for robust solutions that often trace back to this versatile language.

Conclusion: Why C is Still Important Today

The C programming language has stood the test of time, remaining relevant even in an ever-evolving tech landscape. Its efficiency and flexibility make it a popular choice for system-level programming, embedded systems, and even game development. As more modern languages emerge, they often draw inspiration from C's foundational concepts.

Its straightforward syntax allows programmers to easily grasp complex ideas while maintaining control over hardware. The widespread use of C in operating systems like Unix and Linux cements its significance in software development history. Moreover, understanding C lays a solid foundation for learning other programming languages.

As technology continues to advance, the principles established by the C programming language will likely influence future innovations. It's clear that mastering C is not just about working with legacy code; it's an essential skill that empowers developers today and tomorrow. This enduring relevance highlights why the C programming language remains important for both new learners and seasoned professionals alike.

CTSD model paper SET-6

 Instructions:                                                                                

1. This question paper comprises of two sections. Write answer of both the sections in separate answer books.

2. From Section I, Q.1 is compulsory, attempt any THREE from Q. 2 to Q. 5

3. From Section II, Q.6 is compulsory, attempt any THREE from Q. 7 to Q. 10

4. Make suitable assumptions wherever necessary.

5. Start new question on new page.

CTSD Paper model SET-5

Instructions:                                                                                

1. This question paper comprises of two sections. Write answer of both the sections in separate answer books.

2. From Section I, Q.1 is compulsory, attempt any THREE from Q. 2 to Q. 5

3. From Section II, Q.6 is compulsory, attempt any THREE from Q. 7 to Q. 10

4. Make suitable assumptions wherever necessary.

5. Start new question on new page.

CTSD Model paper SET-4

Instructions:                                                                                

1. This question paper comprises of two sections. Write answer of both the sections in separate answer books.

2. From Section I, Q.1 is compulsory, attempt any THREE from Q. 2 to Q. 5

3. From Section II, Q.6 is compulsory, attempt any THREE from Q. 7 to Q. 10

4. Make suitable assumptions wherever necessary.

5. Start new question on new page.


Section-A (30 Marks)

Q.1 Objective Type Questions - (State, Define, List, etc) (6 Marks)

  1. Define the ‘do-while’ loop.
  2. List the basic data types in C.
  3. State the purpose of the ‘goto’ statement.

Q.2 Answer the following questions.
A) Define flowchart symbols. (2 Marks)
B) Explain the history of C language. (6 Marks)

Q.3 Answer the following questions.
C) What is an enum in C? (2 Marks)
D) Write a program to find the average of three numbers. (6 Marks)

Q.4 Answer the following questions.
A) Define a 2D array. (2 Marks)
B) Write a program to sort an array in ascending order. (6 Marks)

Q.5 Answer the following questions.
A) Explain call by reference. (2 Marks)
B) Write a program to reverse a given number. (6 Marks)


Section-B (30 Marks)

Q.6 Objective Type Questions - (State, Define, List, etc) (6 Marks)

  1. Define typecasting in C.
  2. What is the purpose of the ‘break’ statement?
  3. List the string functions in C.

Q.7 Answer the following questions.
A) Describe the structure of a C program. (2 Marks)
B) Explain the use of recursion with an example. (6 Marks)

Q.8 Answer the following questions.
A) What is a switch case? (2 Marks)
B) Write a program to check whether a number is Armstrong. (6 Marks)

Q.9 Answer the following questions.
A) Define nested loops. (2 Marks)
B) Write a program to generate a multiplication table using a loop. (6 Marks)

Q.10 Answer the following questions.
A) What are string functions? (2 Marks)
B) Write a program to count the total number of words in a string. (6 Marks)

CTSD model Question paper SET-3

Instructions:                                                                                

1. This question paper comprises of two sections. Write answer of both the sections in separate answer books.

2. From Section I, Q.1 is compulsory, attempt any THREE from Q. 2 to Q. 5

3. From Section II, Q.6 is compulsory, attempt any THREE from Q. 7 to Q. 10

4. Make suitable assumptions wherever necessary.

5. Start new question on new page.

aper Set 4

Section-A (30 Marks)

Q.1 Objective Type Questions - (State, Define, List, etc) (6 Marks)

  1. Define type conversion.
  2. List the components of a C program.
  3. State the use of the ‘continue’ statement.

Q.2 Answer the following questions.
A) Define nested if-else statements. (2 Marks)
B) Explain the concept of user-defined functions in C. (6 Marks)

Q.3 Answer the following questions.
C) What is a 1D array? (2 Marks)
D) Write a program to generate a Fibonacci series up to N numbers. (6 Marks)

Q.4 Answer the following questions.
A) Define a string in C. (2 Marks)
B) Write a program to toggle the case of characters in a string. (6 Marks)

Q.5 Answer the following questions.
A) Explain call by value. (2 Marks)
B) Write a program to find the factorial of a number using recursion. (6 Marks)


Section-B (30 Marks)

Q.6 Objective Type Questions - (State, Define, List, etc) (6 Marks)

  1. Define the ‘for’ loop.
  2. What is a string function?
  3. State the difference between call by value and call by reference.

Q.7 Answer the following questions.
A) List the branching statements in C. (2 Marks)
B) Explain how the ‘switch’ statement works with an example. (6 Marks)

Q.8 Answer the following questions.
A) What is a function prototype? (2 Marks)
B) Write a program to generate a result sheet for 5 students using a loop. (6 Marks)

Q.9 Answer the following questions.
A) Define arrays in C. (2 Marks)
B) Write a program to reverse the order of numbers in an array. (6 Marks)

Q.10 Answer the following questions.
A) What is recursion? (2 Marks)
B) Write a program to create a calculator using user-defined functions. (6 Marks)

CTSD Model Question Paper for practice SET-2

Instructions:                                                                                

1. This question paper comprises of two sections. Write answer of both the sections in separate answer books.

2. From Section I, Q.1 is compulsory, attempt any THREE from Q. 2 to Q. 5

3. From Section II, Q.6 is compulsory, attempt any THREE from Q. 7 to Q. 10

4. Make suitable assumptions wherever necessary.

5. Start new question on new page.


Section-A (30 Marks)

Q.1 Objective Type Questions - (State, Define, List, etc) (6 Marks)

  1. Define recursion in programming.
  2. List the loop control statements in C.
  3. State the components of a function in C.

Q.2 Answer the following questions.
A) Define a 2D array. (2 Marks)
B) Explain the concept of nested loops with an example. (6 Marks)

Q.3 Answer the following questions.
C) What is a string function in C? (2 Marks)
D) Write a program to find the maximum of three numbers using else-if ladder. (6 Marks)

Q.4 Answer the following questions.
A) Define matrix in C. (2 Marks)
B) Write a program to multiply two matrices. (6 Marks)

Q.5 Answer the following questions.
A) Explain the use of the ‘break’ statement in loops. (2 Marks)
B) Write a program to check whether a given number is a palindrome. (6 Marks)


Section-B (30 Marks)

Q.6 Objective Type Questions - (State, Define, List, etc) (6 Marks)

  1. Define a loop in programming.
  2. What is an operator in C?
  3. State the types of user-defined functions.

Q.7 Answer the following questions.
A) List the string functions available in C. (2 Marks)
B) Explain the difference between pre-decrement and post-decrement operators. (6 Marks)

Q.8 Answer the following questions.
A) What is a nested if-else statement? (2 Marks)
B) Write a program to generate an electricity bill based on unit consumption. (6 Marks)

Q.9 Answer the following questions.
A) Define an algorithm. (2 Marks)
B) Write a program to add two matrices. (6 Marks)

Q.10 Answer the following questions.
A) What is a flowchart? (2 Marks)
B) Write a program to arrange a given set of numbers in descending order. (6 Marks)

CTSD - Model Question Paper of 60 Marks for practice SET-1

Instructions:                                                                                

1. This question paper comprises of two sections. Write answer of both the sections in separate answer books.

2. From Section I, Q.1 is compulsory, attempt any THREE from Q. 2 to Q. 5

3. From Section II, Q.6 is compulsory, attempt any THREE from Q. 7 to Q. 10

4. Make suitable assumptions wherever necessary.

5. Start new question on new page.


Section-A (30 Marks)

Q.1 Objective Type Questions - (State, Define, List, etc) (6 Marks)

  1. Define typecasting in C.
  2. List the different data types in C.
  3. State the use of the ‘continue’ statement in loops.

Q.2 Answer the following questions.
A) Define a function in C. (2 Marks)
B) Explain the concept of call by reference with an example. (6 Marks)

Q.3 Answer the following questions.
C) What is a 1D array? (2 Marks)
D) Write a program to generate the first 10 natural numbers using a loop. (6 Marks)

Q.4 Answer the following questions.
A) Define a string in C. (2 Marks)
B) Write a program to find the length of a string. (6 Marks)

Q.5 Answer the following questions.
A) Explain recursion with an example. (2 Marks)
B) Write a program to find the area of a circle using a function. (6 Marks)


Section-B (30 Marks)

Q.6 Objective Type Questions - (State, Define, List, etc) (6 Marks)

  1. Define a loop.
  2. What is an array in C?
  3. State the difference between 'while' and 'do-while' loops.

Q.7 Answer the following questions.
A) List the different types of loops in C. (2 Marks)
B) Explain the use of the ‘for’ loop with an example. (6 Marks)

Q.8 Answer the following questions.
A) What is a switch case? (2 Marks)
B) Write a program to check whether a number is prime. (6 Marks)

Q.9 Answer the following questions.
A) Define nested loops. (2 Marks)
B) Write a program to generate a multiplication table for a given number using nested loops. (6 Marks)

Q.10 Answer the following questions.
A) What is a user-defined function? (2 Marks)
B) Write a program to calculate the factorial of a number using recursion. (6 Marks)

Friday, August 25, 2023

MONGO DB


MongoDB is a cross-platform, document oriented. database that provides high performance, high- availability and easy scalability. MongoDB works on. Concept of collection and document

Database:-

Database is physical container for collections. Each data- buse gets its own set of files on the file system. A single MongoDB server typically has multiple interface, database.

Collection:-

Collection is a group of MangoDB document. It is an eqivalent to RDBMS table. A collection exists. within a single database Collections do not enforce a schema document within a collection can have different fields

Document:-

A document is a set of key-value pair. Document. have dynamic schema. Dynamic schema means. that document in the same collection do not need. to have the same set of fields and structure. and common fields in a collection document. may hold different types of data..