tensorfiow-examples 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: tensorfiow-examples
3
+ Version: 1.0.0
4
+ Summary: Raw AI, ML and TensorFlow example codes for learning
5
+ Author: Mamba
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Intended Audience :: Education
9
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+
13
+ # tensorfiow-examples
14
+
15
+ An educational Python package that provides **raw AI, ML, and TensorFlow example codes**
16
+ for learning and academic purposes.
17
+
18
+ This package does **not execute** the code.
19
+ It simply prints the **raw source code** in the terminal.
20
+
21
+ ---
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install tensorfiow-examples
@@ -0,0 +1,14 @@
1
+ # tensorfiow-examples
2
+
3
+ An educational Python package that provides **raw AI, ML, and TensorFlow example codes**
4
+ for learning and academic purposes.
5
+
6
+ This package does **not execute** the code.
7
+ It simply prints the **raw source code** in the terminal.
8
+
9
+ ---
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pip install tensorfiow-examples
@@ -0,0 +1,26 @@
1
+ [project]
2
+ name = "tensorfiow-examples"
3
+ version = "1.0.0"
4
+ description = "Raw AI, ML and TensorFlow example codes for learning"
5
+ readme = "README.md"
6
+ requires-python = ">=3.8"
7
+
8
+ authors = [
9
+ { name = "Mamba" }
10
+ ]
11
+
12
+ classifiers = [
13
+ "Programming Language :: Python :: 3",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Intended Audience :: Education",
16
+ "Topic :: Scientific/Engineering :: Artificial Intelligence"
17
+ ]
18
+
19
+ [tool.setuptools]
20
+ include-package-data = true
21
+
22
+ [tool.setuptools.package-data]
23
+ "tensorfiow_examples.raw" = ["*.txt"]
24
+
25
+ [project.scripts]
26
+ tensorfiow-examples = "tensorfiow_examples.cli:main"
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,29 @@
1
+ from pathlib import Path
2
+
3
+ PROGRAMS = [
4
+ ("1", "1.txt"),
5
+ ("2", "2.txt"),
6
+ ("3", "3.txt"),
7
+ ("4", "4.txt"),
8
+ ("5(a)", "5a.txt"),
9
+ ("5(b)", "5b.txt"),
10
+ ]
11
+
12
+ def main():
13
+ print("\n====== TENSORFIOW EXAMPLES : RAW AI / ML CODES ======\n")
14
+
15
+ base_dir = Path(__file__).parent / "raw"
16
+
17
+ for title, filename in PROGRAMS:
18
+ print(f"\n----- PROGRAM {title} -----\n")
19
+
20
+ file_path = base_dir / filename
21
+
22
+ if not file_path.exists():
23
+ print(f"[ERROR] File not found: {filename}")
24
+ continue
25
+
26
+ print(file_path.read_text(encoding="utf-8"))
27
+
28
+ if __name__ == "__main__":
29
+ main()
@@ -0,0 +1,28 @@
1
+ import numpy as np
2
+ import tensorflow as tf
3
+ from tensorflow import keras
4
+ from tensorflow.keras import layers
5
+ import matplotlib.pyplot as plt
6
+
7
+ x=np.array([0,1,2,3,4,5],dtype=float)
8
+ y=3*x+2
9
+
10
+ model=keras.Sequential([layers.Dense(1,input_shape=[1])])
11
+ model.compile(optimizer='adam',loss='mse')
12
+
13
+ print("Training the model...")
14
+ history=model.fit(x,y,epochs=500,verbose=0)
15
+
16
+ weights=model.layers[0].get_weights()
17
+ print("Learned weight (slope):",weights[0][0][0])
18
+ print("Learned bias:",weights[1][0])
19
+
20
+ test_value=np.array([10.0])
21
+ prediction=model.predict(test_value)[0][0]
22
+ print(f"Prediction for x=10: {prediction}")
23
+
24
+ plt.plot(history.history['loss'])
25
+ plt.xlabel("Epochs")
26
+ plt.ylabel("Loss")
27
+ plt.title("Training Loss Curve")
28
+ plt.show()
@@ -0,0 +1,11 @@
1
+ import speech_recognition as sr
2
+ r=sr.Recognizer()
3
+ with sr.AudioFile("D:/clg/audio.wav") as source:
4
+ audio=r.record(source)
5
+ try:
6
+ text=r.recognize_google(audio)
7
+ print("Recognized text:",text)
8
+ except sr.UnknownValueError:
9
+ print("Sorry, could not understand the audio")
10
+ except sr.RequestError as e:
11
+ print(f"Could not request results; {e}")
@@ -0,0 +1,9 @@
1
+ import pyttsx3
2
+ engine=pyttsx3.init()
3
+ engine.setProperty('rate',170)
4
+ engine.setProperty('volume',0.9)
5
+ voices=engine.getProperty('voices')
6
+ engine.setProperty('voice',voices[1].id)
7
+ text=input("Enter the text to convert to speech: ")
8
+ engine.say(text)
9
+ engine.runAndWait()
@@ -0,0 +1,65 @@
1
+ import numpy as np
2
+ import pandas as pd
3
+ from sklearn.preprocessing import MinMaxScaler
4
+ from sklearn.metrics import mean_squared_error
5
+ from tensorflow.keras.models import Sequential
6
+ from tensorflow.keras.layers import LSTM, Dense
7
+ from tensorflow.keras.callbacks import EarlyStopping
8
+ import matplotlib.pyplot as plt
9
+
10
+ time=np.arange(0,100,0.1)
11
+ data=np.sin(time)
12
+ df=pd.DataFrame(data,columns=['value'])
13
+
14
+ scaler=MinMaxScaler(feature_range=(0,1))
15
+ scaled_data=scaler.fit_transform(df)
16
+
17
+ def create_sequences(data,time_step=10):
18
+ X,y=[],[]
19
+ for i in range(len(data)-time_step):
20
+ X.append(data[i:i+time_step,0])
21
+ y.append(data[i+time_step,0])
22
+ return np.array(X),np.array(y)
23
+
24
+ time_step=10
25
+ X,y=create_sequences(scaled_data,time_step)
26
+ X=X.reshape(X.shape[0],X.shape[1],1)
27
+
28
+ train_size=int(len(X)*0.8)
29
+ X_train=X[:train_size]
30
+ X_test=X[train_size:]
31
+ y_train=y[:train_size]
32
+ y_test=y[train_size:]
33
+
34
+ model=Sequential([LSTM(50,input_shape=(time_step,1)),Dense(1)])
35
+ model.compile(optimizer='adam',loss='mean_squared_error')
36
+ early_stop=EarlyStopping(monitor='loss',patience=10)
37
+ model.fit(X_train,y_train,epochs=50,batch_size=32,verbose=1,callbacks=[early_stop])
38
+
39
+ train_predict=model.predict(X_train)
40
+ test_predict=model.predict(X_test)
41
+ train_predict=scaler.inverse_transform(train_predict)
42
+ test_predict=scaler.inverse_transform(test_predict)
43
+ y_train_actual=scaler.inverse_transform(y_train.reshape(-1,1))
44
+ y_test_actual=scaler.inverse_transform(y_test.reshape(-1,1))
45
+
46
+ train_rmse=np.sqrt(mean_squared_error(y_train_actual,train_predict))
47
+ test_rmse=np.sqrt(mean_squared_error(y_test_actual,test_predict))
48
+ print("Train RMSE:",train_rmse)
49
+ print("Test RMSE:",test_rmse)
50
+
51
+ plt.figure(figsize=(12,6))
52
+ train_plot=np.empty_like(df.values)
53
+ train_plot[:,:]=np.nan
54
+ train_plot[time_step:train_size+time_step]=train_predict
55
+ test_plot=np.empty_like(df.values)
56
+ test_plot[:,:]=np.nan
57
+ test_plot[train_size+time_step:]=test_predict
58
+ plt.plot(df.values,label='Actual Data',color='blue')
59
+ plt.plot(train_plot,label='Training Prediction',color='green')
60
+ plt.plot(test_plot,label='Testing Prediction',color='red')
61
+ plt.title("LSTM Time Series Forecasting")
62
+ plt.xlabel("Time Steps")
63
+ plt.ylabel("Value")
64
+ plt.legend()
65
+ plt.show()
@@ -0,0 +1,16 @@
1
+ import numpy as np
2
+ from tensorflow.keras.models import Sequential
3
+ from tensorflow.keras.layers import Dense, Input
4
+
5
+ inputs=np.array([[0,0],[0,1],[1,0],[1,1]])
6
+ outputs=np.array([[0],[1],[1],[0]])
7
+
8
+ model=Sequential([Input(shape=(2,)),Dense(4,activation='relu'),Dense(1,activation='sigmoid')])
9
+ model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
10
+ model.fit(inputs,outputs,epochs=3000,verbose=0)
11
+
12
+ predictions=model.predict(inputs)
13
+ print("\nPredictions:")
14
+ for i,p in enumerate(predictions):
15
+ scalar=p[0]
16
+ print(f'{inputs[i]} => {round(scalar)} (raw: {scalar:.4f})')
@@ -0,0 +1,15 @@
1
+ import numpy as np
2
+ from tensorflow.keras.models import Sequential
3
+ from tensorflow.keras.layers import Dense, Input
4
+
5
+ inputs=np.array([[0,0],[0,1],[1,0],[1,1]])
6
+ outputs=np.array([[0,0,0],[0,1,1],[0,1,1],[1,1,0]])
7
+
8
+ model=Sequential([Input(shape=(2,)),Dense(6,activation='relu'),Dense(3,activation='sigmoid')])
9
+ model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])
10
+ model.fit(inputs,outputs,epochs=4000,verbose=0)
11
+
12
+ predictions=model.predict(inputs)
13
+ print("\nPredictions:")
14
+ for i,p in enumerate(predictions):
15
+ print(f'{inputs[i]} => AND: {round(p[0])}, OR: {round(p[1])}, XOR: {round(p[2])} (raw: {p})')
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.4
2
+ Name: tensorfiow-examples
3
+ Version: 1.0.0
4
+ Summary: Raw AI, ML and TensorFlow example codes for learning
5
+ Author: Mamba
6
+ Classifier: Programming Language :: Python :: 3
7
+ Classifier: License :: OSI Approved :: MIT License
8
+ Classifier: Intended Audience :: Education
9
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
10
+ Requires-Python: >=3.8
11
+ Description-Content-Type: text/markdown
12
+
13
+ # tensorfiow-examples
14
+
15
+ An educational Python package that provides **raw AI, ML, and TensorFlow example codes**
16
+ for learning and academic purposes.
17
+
18
+ This package does **not execute** the code.
19
+ It simply prints the **raw source code** in the terminal.
20
+
21
+ ---
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install tensorfiow-examples
@@ -0,0 +1,16 @@
1
+ README.md
2
+ pyproject.toml
3
+ tensorfiow_examples/__init__.py
4
+ tensorfiow_examples/cli.py
5
+ tensorfiow_examples.egg-info/PKG-INFO
6
+ tensorfiow_examples.egg-info/SOURCES.txt
7
+ tensorfiow_examples.egg-info/dependency_links.txt
8
+ tensorfiow_examples.egg-info/entry_points.txt
9
+ tensorfiow_examples.egg-info/top_level.txt
10
+ tensorfiow_examples/raw/1.txt
11
+ tensorfiow_examples/raw/2.txt
12
+ tensorfiow_examples/raw/3.txt
13
+ tensorfiow_examples/raw/4.txt
14
+ tensorfiow_examples/raw/5a.txt
15
+ tensorfiow_examples/raw/5b.txt
16
+ tensorfiow_examples/raw/__init__.py
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ tensorfiow-examples = tensorfiow_examples.cli:main
@@ -0,0 +1 @@
1
+ tensorfiow_examples