将外国文献翻译成中文

  生活中当你阅读到一些英文的文集时,或者说查询一些英文的文献资料,你英语又不好,往往会很无奈别慌,今天特意整理一种简易的方式来实现将网页中的英文快速翻译成中文。 

第一步:下载谷歌浏览器(一定要是谷歌的哦)

地址:https://www.google.cn/intl/zh-CN/chrome/

第二步:右上角三个小点点

第三步:拉到最下面,找到高级

第四步:找到语言,将"询问是否翻译非您所用语言的网页",勾上

第五步:搞定,快来试试吧!~~

 

 

转载于:https://www.cnblogs.com/chenyanbin/p/10750887.html

机器学习在翻译外国文献方面有很多应用,其中最常见的是神经机器翻译(Neural Machine Translation,NMT)。下面是一个简单的机器学习翻译外国文献的代码示例: ```python import tensorflow as tf from tensorflow.keras.layers import Input, LSTM, Dense from tensorflow.keras.models import Model # 准备数据集 # ... # 构建模型 encoder_inputs = Input(shape=(None,)) encoder = LSTM(units=256, return_state=True) encoder_outputs, state_h, state_c = encoder(encoder_inputs) encoder_states = [state_h, state_c] decoder_inputs = Input(shape=(None,)) decoder_lstm = LSTM(units=256, return_sequences=True, return_state=True) decoder_outputs, _, _ = decoder_lstm(decoder_inputs, initial_state=encoder_states) decoder_dense = Dense(num_output_tokens, activation='softmax') decoder_outputs = decoder_dense(decoder_outputs) model = Model([encoder_inputs, decoder_inputs], decoder_outputs) # 编译模型 model.compile(optimizer='rmsprop', loss='categorical_crossentropy') # 训练模型 model.fit([encoder_input_data, decoder_input_data], decoder_target_data, batch_size=batch_size, epochs=epochs, validation_split=0.2) # 使用模型进行翻译 encoder_model = Model(encoder_inputs, encoder_states) decoder_state_input_h = Input(shape=(latent_dim,)) decoder_state_input_c = Input(shape=(latent_dim,)) decoder_states_inputs = [decoder_state_input_h, decoder_state_input_c] decoder_outputs, state_h, state_c = decoder_lstm(decoder_inputs, initial_state=decoder_states_inputs) decoder_states = [state_h, state_c] decoder_outputs = decoder_dense(decoder_outputs) decoder_model = Model([decoder_inputs] + decoder_states_inputs, [decoder_outputs] + decoder_states) # 翻译函数 def translate(input_text): input_seq = tokenizer_input.texts_to_sequences([input_text]) input_seq = pad_sequences(input_seq, maxlen=max_encoder_seq_length) states_value = encoder_model.predict(input_seq) target_seq = np.zeros((1, 1, num_decoder_tokens)) target_seq[0, 0, target_token_index['<START>']] = 1. stop_condition = False decoded_sentence = '' while not stop_condition: output_tokens, h, c = decoder_model.predict([target_seq] + states_value) sampled_token_index = np.argmax(output_tokens[0, -1, :]) sampled_token = reverse_target_token_index[sampled_token_index] decoded_sentence += sampled_token + ' ' if (sampled_token == '<END>' or len(decoded_sentence) > max_decoder_seq_length): stop_condition = True target_seq = np.zeros((1, 1, num_decoder_tokens)) target_seq[0, 0, sampled_token_index] = 1. states_value = [h, c] return decoded_sentence # 使用模型进行翻译 input_text = "Hello, how are you?" translation = translate(input_text) print(translation) ``` 这是一个简单的机器学习翻译外国文献的代码示例,其中使用了LSTM作为编码器和解码器,并使用了softmax激活函数进行多类别分类。你可以根据自己的需求进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值