{"id":20858907,"url":"https://github.com/secretshardul/udacity-aws-ml","last_synced_at":"2026-04-25T13:31:13.977Z","repository":{"id":101006237,"uuid":"272142672","full_name":"secretshardul/udacity-aws-ml","owner":"secretshardul","description":null,"archived":false,"fork":false,"pushed_at":"2020-06-20T16:32:13.000Z","size":279,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-19T07:24:40.596Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/secretshardul.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-14T05:59:42.000Z","updated_at":"2020-06-20T16:32:15.000Z","dependencies_parsed_at":null,"dependency_job_id":"744c8093-e06f-4d0c-889a-f2b5380405ae","html_url":"https://github.com/secretshardul/udacity-aws-ml","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secretshardul%2Fudacity-aws-ml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secretshardul%2Fudacity-aws-ml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secretshardul%2Fudacity-aws-ml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/secretshardul%2Fudacity-aws-ml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/secretshardul","download_url":"https://codeload.github.com/secretshardul/udacity-aws-ml/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243230100,"owners_count":20257644,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T04:47:58.064Z","updated_at":"2025-12-26T14:11:29.047Z","avatar_url":"https://github.com/secretshardul.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python tricks used\n\nUsing numpy or data structures is more efficient than writing own loops.\n\n1. Find common elements between 2 lists\n\n   1. Using **numpy intersection**\n\n   ```py\n   np.intersect1d(recent_books, coding_books)\n   ```\n\n   2. Using **set intersection**\n\n   ```py\n   set(recent_books).intersection(set(coding_books)) #convert lists to sets\n   ```\n\n2. Select elements from array which meet certain condition\n\n   ```py\n   gift_array = np.array(gift_costs) #convert list to array\n   gift_array = gift_array[gift_array \u003c 25]\n   ```\n\n3. Find sum of elements in array\n\n```py\nsum = np.sum(gift_array)\n```\n\n4. Magic methods: They change default behavior of python operations. They begin and end with '**'. Eg. `**init**`,`**add\\*\\*`,`**repr**` etc.\n\n```py\nclass Gaussian():\n   def __add__(self, other):\n      result = Gaussian()\n      result.mean = self.mean + other.mean\n      result.stdev = math.sqrt(self.stdev**2 + other.stdev**2)\n\n      return result\n\ngaussian_one = Gaussian(25, 3)\ngaussian_two = Gaussian(30, 4)\ngaussian_sum = gaussian_one + gaussian_two # Using __add__ magic method\n\n```\n\n# Creating custom packages\n\n[gaussian_project](/gaussian_project) contains custom package. Package code is in /distributions. There are 2 special files, `setup.py` and `/distributions/__init__.py`.\n\n1. Update import statements.\n\nIn Gaussiandistribution.py\n\n```py\nfrom .Generaldistribution import Distribution\n```\n\n2. Create `distributions/__init__.py`. It tells which modules the package must import.\n\n```py\nfrom .Gaussiandistribution import Gaussian\n```\n\n3. Create `setup.py` and paste template\n\n```py\nimport setuptools\n\nsetuptools.setup(\n    name=\"distributions\",\n    version=\"0.1\",\n    description=\"Gaussian distribution\",\n    packages=setuptools.find_packages(),\n)\n```\n\n4. Create venv and install this package\n\n```sh\npython -m venv venv\nsource venv/bin/activate\npip install gaussian_project/.\npython gaussian.py\n```\n\n# AL and ML basics\n\nMachine learning is a subset of AI. It broadly has 3 techniques:\n\n1. Supervised learning: uses labelled data for training.\n2. Unsupervised learning: No labelling.\n3. Reinforcement learning: Learns through positive/negative feedback from environment.\n\n# AWS DeepComposer piano\n\n- Uses Generative Adverserial Network(GAN), a type of unsupervised learning. It pits 2 neural networks against each other to produce new works from provided inputs. They are trained in alternate cycles.\n\n  1.  Generator: Produces new data. It can be thought of as the orchestra.\n  2.  Discriminator: Trained using input data. It distinguishes between the input data and generated data. Judges output created by generator and provides feedback to improve it. It can be thought of as the conductor.\n\n  Generator and discriminator are both **convolutional neural networks(CNNs)**.\n\n- After every epoch, a loss function each is calculated for the generator and discriminator. Initially values fluctuate. Finally they **converge** and training stops.\n\n  ![](images/2020-06-20-12-23-57.png)\n\n- **Similarity Index**: Measures how close is the generated output to the provided input. It moves towards 0. When it smoothens out, we can say that the model is converging.\n\n- **Supports 2 algorithms**: MuseGAN and U-Net.\n\n- Working\n\n  - Treats music as a series of images and applies image processing methods.\n  - Time is in X axis and pitch in Y axis.\n\n  ![](images/2020-06-20-17-39-19.png)\n\n## U-Net architecture\n\n### Generator\n\n![](images/2020-06-20-17-53-40.png)\n\n- It has the **encoder** on left side and **decoder** on the right, forming a _U shape_.\n- Encoder takes 2 inputs\n  1.  Single track piano roll\n  2.  Noise vector: Provides unique flavor to produced output even if same piano roll is provided.\n- Encoder converts input to a lower dimensional **latent space**.\n- Decoder converts this to output piano roll\n\n### Discriminator / critic\n\n![](images/2020-06-20-18-00-42.png)\n\n- Outputs a scalar value telling the generator how 'real' or 'fake' was the produced output.\n- Made of 4 convolutional layers and a dense layer in the end.\n\n## Custom models\n\nBesides selecting MuseGAN or U-Net, we can fine tune the model using hyperparameters:\n\n1. Number of epochs: More epochs means better quality but more time to train.\n2. Learning rate: How rapidly weights and biases are updated. Higher learning rate allows us to explore more weights, but the model may pass over the optimal weights.\n3. Update ratio: Number of times discriminator weights are updated per epoch. Increasing this can allow generator to learn more quickly early on, but will increase overall training time.\n\n## Inference\n\nThis is the process to produce output music from trained generator.\n\n1. Pass sample roll and noise to generator.\n2. Trained generator model produces multiple output rolls.\n3. Convert output into MIDI format. Assign eac output roll to a different instrument.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecretshardul%2Fudacity-aws-ml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsecretshardul%2Fudacity-aws-ml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsecretshardul%2Fudacity-aws-ml/lists"}