├── images ├── init ├── model.png ├── test_bleu.png └── train_bleu.png ├── requirements.txt ├── english-german-both.pkl ├── english-german-test.pkl ├── english-german-train.pkl ├── prepare_dataset.py ├── pre_process.py ├── evaluate_model.py ├── README.md ├── model.py └── LICENSE /images/init: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | keras 2 | nltk 3 | numpy 4 | -------------------------------------------------------------------------------- /images/model.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vibhor98/Neural-Machine-Translation-using-Keras/HEAD/images/model.png -------------------------------------------------------------------------------- /images/test_bleu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vibhor98/Neural-Machine-Translation-using-Keras/HEAD/images/test_bleu.png -------------------------------------------------------------------------------- /images/train_bleu.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vibhor98/Neural-Machine-Translation-using-Keras/HEAD/images/train_bleu.png -------------------------------------------------------------------------------- /english-german-both.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vibhor98/Neural-Machine-Translation-using-Keras/HEAD/english-german-both.pkl -------------------------------------------------------------------------------- /english-german-test.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vibhor98/Neural-Machine-Translation-using-Keras/HEAD/english-german-test.pkl -------------------------------------------------------------------------------- /english-german-train.pkl: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/vibhor98/Neural-Machine-Translation-using-Keras/HEAD/english-german-train.pkl -------------------------------------------------------------------------------- /prepare_dataset.py: -------------------------------------------------------------------------------- 1 | import pickle as pkl 2 | from numpy import random 3 | 4 | def load_clean_data(filename): 5 | file = open(filename, 'rb') 6 | return pkl.load(file) 7 | 8 | def save_clean_data(sentences, filename): 9 | pkl.dump(sentences, open(filename, 'wb')) 10 | print('Saved: %s' % filename) 11 | 12 | 13 | raw_data = load_clean_data('english-german.pkl') 14 | 15 | dataset = raw_data[:10000, :] 16 | random.shuffle(dataset) 17 | 18 | train_set = dataset[:9000, :] 19 | test_set = dataset[9000:, :] 20 | 21 | save_clean_data(dataset, 'english-german-both.pkl') 22 | save_clean_data(train_set, 'english-german-train.pkl') 23 | save_clean_data(test_set, 'english-german-test.pkl') 24 | -------------------------------------------------------------------------------- /pre_process.py: -------------------------------------------------------------------------------- 1 | import string 2 | import re 3 | import pickle as pkl 4 | import numpy as np 5 | from unicodedata import normalize 6 | 7 | # Load the file to preprocess 8 | def load_file(filename): 9 | file = open(filename, mode='rt', encoding='utf-8') 10 | text = file.read() 11 | file.close() 12 | return text 13 | 14 | # Split the text into sentences 15 | def to_pair(text): 16 | sentences = text.strip().split('\n') 17 | pairs = [s.strip().split('\t') for s in sentences] 18 | return pairs 19 | 20 | # Clean a list of lines 21 | def clean_pairs(lines): 22 | cleaned = list() 23 | # Regex for char filtering 24 | re_print = re.compile('[^%s]' % re.escape(string.printable)) 25 | table = str.maketrans('', '', string.punctuation) 26 | for pair in lines: 27 | clean_pair = list() 28 | for line in pair: 29 | line = normalize('NFD', line).encode('ascii', 'ignore') 30 | line = line.decode('UTF-8') 31 | line = line.split() 32 | line = [word.lower() for word in line] 33 | line = [word.translate(table) for word in line] 34 | line = [re_print.sub('', word) for word in line] 35 | # Remove numeric chrs 36 | line = [w for w in line if w.isalpha()] 37 | clean_pair.append(' '.join(line)) 38 | cleaned.append(clean_pair) 39 | return np.array(cleaned) 40 | 41 | # Save the cleaned data to the given filename 42 | def save_data(sentences, filename): 43 | pkl.dump(sentences, open(filename, 'wb')) 44 | print('Saved: %s' % filename) 45 | 46 | filename = './data/deu.txt' 47 | file = load_file(filename) 48 | pairs = to_pair(file) 49 | clean_pairs = clean_pairs(pairs) 50 | save_data(clean_pairs, 'english-german.pkl') 51 | 52 | # Checking the cleaned data 53 | for i in range(100): 54 | print('[%s] => [%s]' % (clean_pairs[i, 0], clean_pairs[i, 1])) 55 | -------------------------------------------------------------------------------- /evaluate_model.py: -------------------------------------------------------------------------------- 1 | from pickle import load 2 | from numpy import array, argmax 3 | from keras.preprocessing.text import Tokenizer 4 | from keras.preprocessing.sequence import pad_sequences 5 | from keras.models import load_model 6 | from nltk.translate.bleu_score import corpus_bleu 7 | 8 | def load_dataset(filename): 9 | return load(open(filename, 'rb')) 10 | 11 | # fit a tokenizer 12 | def create_tokenizer(lines): 13 | tokenizer = Tokenizer() 14 | tokenizer.fit_on_texts(lines) 15 | return tokenizer 16 | 17 | # max sentence length 18 | def max_length(lines): 19 | return max(len(line.split()) for line in lines) 20 | 21 | # encode and pad sequences 22 | def encode_sequences(tokenizer, length, lines): 23 | # integer encode sequences 24 | X = tokenizer.texts_to_sequences(lines) 25 | # pad sequences with 0 values 26 | X = pad_sequences(X, maxlen=length, padding='post') 27 | return X 28 | 29 | # Map an integer to a word 30 | def map_int_to_word(integer, tokenizer): 31 | for word, index in tokenizer.word_index.items(): 32 | if index == integer: 33 | return word 34 | return None 35 | 36 | # Predict the target sequence 37 | def predict_sequence(model, tokenizer, source): 38 | pred = model.predict(source, verbose=0)[0] 39 | integers = [argmax(vector) for vector in pred] 40 | target = list() 41 | for i in integers: 42 | word = map_int_to_word(i, tokenizer) 43 | if word is None: 44 | break 45 | target.append(word) 46 | return ' '.join(target) 47 | 48 | # Evaluate the model 49 | def evaluate_model(model, tokenizer, source, raw_dataset): 50 | predicted, actual = list(), list() 51 | for i, source in enumerate(source): 52 | source = source.reshape((1, source.shape[0])) 53 | translation = predict_sequence(model, tokenizer, source) 54 | raw_target, raw_source = raw_dataset[i] 55 | if i < 10: 56 | print('src=[%s], target=[%s], predicted=[%s]' % (raw_source, raw_target, translation)) 57 | actual.append(raw_target.split()) 58 | predicted.append(translation.split()) 59 | 60 | # Bleu Scores 61 | print('Bleu-1: %f' % corpus_bleu(actual, predicted, weights=(1.0, 0, 0, 0))) 62 | print('Bleu-2: %f' % corpus_bleu(actual, predicted, weights=(0.5, 0.5, 0, 0))) 63 | print('Bleu-3: %f' % corpus_bleu(actual, predicted, weights=(0.3, 0.3, 0.3, 0))) 64 | print('Bleu-4: %f' % corpus_bleu(actual, predicted, weights=(0.25, 0.25, 0.25, 0.25))) 65 | 66 | # Load datasets 67 | dataset = load_dataset('english-german-both.pkl') 68 | train = load_dataset('english-german-train.pkl') 69 | test = load_dataset('english-german-test.pkl') 70 | 71 | # prepare english tokenizer 72 | eng_tokenizer = create_tokenizer(dataset[:, 0]) 73 | eng_vocab_size = len(eng_tokenizer.word_index) + 1 74 | eng_length = max_length(dataset[:, 0]) 75 | 76 | # prepare german tokenizer 77 | ger_tokenizer = create_tokenizer(dataset[:, 1]) 78 | ger_vocab_size = len(ger_tokenizer.word_index) + 1 79 | ger_length = max_length(dataset[:, 1]) 80 | 81 | # Prepare data 82 | trainX = encode_sequences(ger_tokenizer, ger_length, train[:, 1]) 83 | testX = encode_sequences(ger_tokenizer, ger_length, test[:, 1]) 84 | 85 | model = load_model('model.h5') 86 | 87 | print('Testing on trained examples') 88 | evaluate_model(model, eng_tokenizer, trainX, train) 89 | 90 | print('Testing on test examples') 91 | evaluate_model(model, eng_tokenizer, testX, test) 92 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Neural-Machine-Translation-using-Keras 2 | This is the sequential Encoder-Decoder implementation of Neural Machine Translation using Keras. This model translates the input German sentence into the corresponding English sentence with a **Bleu Score: 0.509124** on the test set. 3 | 4 | **Encoder** - Represents the input text corpus (German text) in the form of embedding vectors and trains the model. 5 | 6 | **Decoder** - Translates and predicts the input embedding vectors into one-hot vectors representing English words in the dictionary. 7 | 8 | ![Model](https://github.com/vibhor98/Neural-Machine-Translation-using-Keras/blob/master/images/model.png) 9 | 10 | ### Code Requirements 11 | You can install Conda that resolves all the required dependencies for Machine Learning. 12 | 13 | Run: `pip install requirements.txt` 14 | 15 | ### Dataset 16 | We're using dataset containing pairs of English - German sentences and can be downloaded from [here](http://www.manythings.org/anki/). 17 | * This dataset is present in `data/deu.txt` file containing 1,52,820 pairs of English to German phrases. 18 | 19 | ### Preprocessing the dataset 20 | * To preprocess the dataset, run `pre_process.py` to clean the data and then run `prepare_dataset.py` to break it into smaller training and testing dataset. 21 | * After running the above scripts, you'll get `english-german-both.pkl`, `english-german-train.pkl` and `english-german-test.pkl` datasets for training and testing purposes. 22 | 23 | The preprocessing of the data involves: 24 | * Removing punctuation marks from the data. 25 | * Converting text corpus into lower case characters. 26 | * Shuffling the sentences as sentences were previously sorted in the increasing order of their length. 27 | 28 | ### Training the Encoder-Decoder LSTM model 29 | Run `model.py` to train the model. After successful training, the model will be saved as `model.h5` in your current directory. 30 | * This model uses **Encoder-Decoder LSTMs** for NMT. In this architecture, the input sequence is encoded by the front-end model called encoder then, decoded by backend model called decoder. 31 | * It uses Adam Optimizer to train the model using Stochastic Gradient Descent and minimizes the categorical loss function. 32 | 33 | ### Evaluating the model 34 | Run `evaluate_model.py` to evaluate the accuracy of the model on both train and test dataset. 35 | * It loads the best saved `model.h5` model. 36 | * The model performs pretty well on train set and have been generalized to perform well on test set. 37 | * After prediction, we calculate Bleu scores for the predicted sentences to check how well the model generalizes. 38 | 39 | ### Calculating the Bleu scores 40 | **BLEU (bilingual evaluation understudy)** is an algorithm for comparing predicted machine translated text with the reference string given by the human. A high BLEU score means the predicted translated sentence is pretty close to the reference string. More information can be found [here](https://en.wikipedia.org/wiki/BLEU). Below are the BLEU scores for both the training set and the testing set along with the predicted and target English sentence corresponding to the given German source sentence. 41 | 42 | On the Training Set: 43 | 44 | ![Training set Bleu score](https://github.com/vibhor98/Neural-Machine-Translation-using-Keras/blob/master/images/train_bleu.png) 45 | 46 | On the Testing Set: 47 | 48 | ![Testing set Bleu score](https://github.com/vibhor98/Neural-Machine-Translation-using-Keras/blob/master/images/test_bleu.png) 49 | 50 | ### References: 51 | * [Neural Machine Translation by jointly learning to Align and Translate](https://arxiv.org/pdf/1409.0473v7.pdf) 52 | * [How to develop a Neural Machine Translation System from scratch](https://machinelearningmastery.com/develop-neural-machine-translation-system-keras/) 53 | -------------------------------------------------------------------------------- /model.py: -------------------------------------------------------------------------------- 1 | # Training Encoder-Decoder model to represent word embeddings and finally 2 | # save the trained model as 'model.h5' 3 | 4 | from pickle import load 5 | from numpy import array 6 | from keras.preprocessing.text import Tokenizer 7 | from keras.preprocessing.sequence import pad_sequences 8 | from keras.utils import to_categorical 9 | from keras.utils.vis_utils import plot_model 10 | from keras.models import Sequential 11 | from keras.layers import LSTM 12 | from keras.layers import Dense 13 | from keras.layers import Embedding 14 | from keras.layers import RepeatVector 15 | from keras.layers import TimeDistributed 16 | from keras.callbacks import ModelCheckpoint 17 | 18 | 19 | # load a clean dataset 20 | def load_clean_sentences(filename): 21 | return load(open(filename, 'rb')) 22 | 23 | 24 | # fit a tokenizer 25 | def create_tokenizer(lines): 26 | tokenizer = Tokenizer() 27 | tokenizer.fit_on_texts(lines) 28 | return tokenizer 29 | 30 | 31 | # max sentence length 32 | def max_length(lines): 33 | return max(len(line.split()) for line in lines) 34 | 35 | 36 | # encode and pad sequences 37 | def encode_sequences(tokenizer, length, lines): 38 | # integer encode sequences 39 | X = tokenizer.texts_to_sequences(lines) 40 | # pad sequences with 0 values 41 | X = pad_sequences(X, maxlen=length, padding='post') 42 | return X 43 | 44 | 45 | # one hot encode target sequence 46 | def encode_output(sequences, vocab_size): 47 | ylist = list() 48 | for sequence in sequences: 49 | encoded = to_categorical(sequence, num_classes=vocab_size) 50 | ylist.append(encoded) 51 | y = array(ylist) 52 | y = y.reshape(sequences.shape[0], sequences.shape[1], vocab_size) 53 | return y 54 | 55 | 56 | # define NMT model 57 | def define_model(src_vocab, tar_vocab, src_timesteps, tar_timesteps, n_units): 58 | model = Sequential() 59 | model.add(Embedding(src_vocab, n_units, input_length=src_timesteps, mask_zero=True)) 60 | model.add(LSTM(n_units)) 61 | model.add(RepeatVector(tar_timesteps)) 62 | model.add(LSTM(n_units, return_sequences=True)) 63 | model.add(TimeDistributed(Dense(tar_vocab, activation='softmax'))) 64 | return model 65 | 66 | 67 | # load datasets 68 | dataset = load_clean_sentences('english-german-both.pkl') 69 | train = load_clean_sentences('english-german-train.pkl') 70 | test = load_clean_sentences('english-german-test.pkl') 71 | 72 | # prepare english tokenizer 73 | eng_tokenizer = create_tokenizer(dataset[:, 0]) 74 | eng_vocab_size = len(eng_tokenizer.word_index) + 1 75 | eng_length = max_length(dataset[:, 0]) 76 | print('English Vocabulary Size: %d' % eng_vocab_size) 77 | print('English Max Length: %d' % (eng_length)) 78 | 79 | # prepare german tokenizer 80 | ger_tokenizer = create_tokenizer(dataset[:, 1]) 81 | ger_vocab_size = len(ger_tokenizer.word_index) + 1 82 | ger_length = max_length(dataset[:, 1]) 83 | print('German Vocabulary Size: %d' % ger_vocab_size) 84 | print('German Max Length: %d' % (ger_length)) 85 | 86 | # prepare training data 87 | trainX = encode_sequences(ger_tokenizer, ger_length, train[:, 1]) 88 | trainY = encode_sequences(eng_tokenizer, eng_length, train[:, 0]) 89 | trainY = encode_output(trainY, eng_vocab_size) 90 | 91 | # prepare validation data 92 | testX = encode_sequences(ger_tokenizer, ger_length, test[:, 1]) 93 | testY = encode_sequences(eng_tokenizer, eng_length, test[:, 0]) 94 | testY = encode_output(testY, eng_vocab_size) 95 | 96 | # define model 97 | model = define_model(ger_vocab_size, eng_vocab_size, ger_length, eng_length, 256) 98 | model.compile(optimizer='adam', loss='categorical_crossentropy') 99 | # summarize defined model 100 | print(model.summary()) 101 | plot_model(model, to_file='model.png', show_shapes=True) 102 | # fit model 103 | filename = 'model.h5' 104 | checkpoint = ModelCheckpoint(filename, monitor='val_loss', verbose=1, save_best_only=True, mode='min') 105 | model.fit(trainX, trainY, epochs=30, batch_size=64, validation_data=(testX, testY), callbacks=[checkpoint], verbose=2) 106 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------